Why We Don't Do Fixed-Price Software Projects
blog.salsitasoft.com3 pointsby iki230 comments
def calculate(a, b, c, memo={}):
try:
value = memo[a, b, c] # return already calculated value
except KeyError:
value = heavy_calculation(a, b, c)
memo[a, b, c] = value # update the memo dictionary
return value def f(x=None): if x is None: x = [] >python wordlist.py -w wordlist -p wordlist.pkl
>python wordlist.py -T wordlist wordlist.pkl 10 3
2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
words(wordfile): 142.50 best msec/loop
words_slower(wordfile): 161.00 best msec/loop
words_normalized(wordfile): 295.84 best msec/loop
words_pickled(pickled): 2943.66 best msec/loop
The winner is: with open(wordfile) as wordlist:
return frozenset(wordlist.read().split('\n'))
Source: https://gist.github.com/1059725 with open('/usr/share/dict/words') as wordlist:
words = set(line[:-1] for line in wordlist)
Or, for one time check you can stop reading on match: import sys
lookup = '%s\n' % sys.argv[1]
with open('/usr/share/dict/words') as wordlist:
[ sys.stdout.write('Dictionary password: %s' % lookup) or sys.exit(1) for line in wordlist if line == lookup ]
As for the objective, this checks only exact dictionary matches. In real world, you'd use cracklib to check any dictionary based or weak passwords rather than reinvent the wheel. See http://gdub.wordpress.com/2006/08/26/using-cracklib-to-requi...