This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
##################################################################### | |
# List of spoken languages taken from Wikipedia: | |
# http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | |
# and translated into a Python list of dictionaries. | |
# | |
# Copyless 2011 Juancarlo Añez <[email protected]> | |
##################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def singleton(cls): | |
class Singleton(cls): | |
def __new__(cls, *args, **kwargs): | |
try: | |
return cls.__instance | |
except AttributeError: | |
cls.__instance = super(Singleton, cls).__new__(cls, *args, **kwargs) | |
cls.instance = cls.__instance | |
return cls.__instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- encoding:utf-8 -*- | |
""" | |
Solution to Project Euler Problem | |
http://projecteuler.net/ | |
by Apalala <[email protected]> | |
(cc) Attribution-ShareAlike | |
http://creativecommons.org/licenses/by-sa/3.0/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.swp | |
*.pyc | |
*.pyo | |
.project | |
.pydevproject | |
.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This is a partial solution because several other operator methods | |
should be overridden for absolute consistency. | |
The complete list is at: | |
http://docs.python.org/2/reference/datamodel.html#emulating-numeric-types | |
http://docs.python.org/3/reference/datamodel.html#emulating-numeric-types | |
''' | |
import math |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
ALPHABET = string.digits + string.ascii_letters | |
def rebase(value, width=1, alphabet=ALPHABET): | |
""" Convert the given integer to the base | |
and symbols of the given alphabet | |
""" | |
n = len(alphabet) | |
result = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from math import sin, cos, radians | |
import timeit | |
''' | |
A simple Python benchmark. | |
Results on an overclocked AMD FX-8150 Eight-Core CPU @ 3.0 GHz, and | |
an Intel Core i5-2410M CPU @ 2.30GHz. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# already sorted | |
for name, group in itertools.groupby(db_iter, key=lambda x: x[0]): | |
total_sales = 0 | |
number_of_sales = 0 | |
earliest_sale = None | |
latest_sale = None | |
for _, amount, date in group: | |
if amount is not None: | |
total_sales += amount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def digito_rif(ci): | |
''' | |
toma un nro de cedula o rif y verifica el digito validador | |
''' | |
base = {'V': 1 * 4, 'E': 2 * 4, 'J': 3 * 4} | |
oper = [0, 3, 2, 7, 6, 5, 4, 3, 2] | |
for i in range(len(ci[:9])): | |
if i == 0: | |
val = base.get(ci[0], 0) | |
else: |