Code golf challenge: XKCD 936 passwords

Nick Cash nick.cash at npcinternational.com
Wed Oct 9 12:07:58 EDT 2013


>> # Python-2, sorry
>> import os
>> print list(set(open('/usr/share/dict/words')))[os.getpid():][:4]

> So that steps by your pid? 

Not really. It seems to rely on list(set(...)) kinda randomizing order... which is definitely not safe without hash randomization.  

But this brings up an interesting concept... if we can assume Python 2.7 with the -R flag, or Python 3.3+, I think we do get true pseudo-randomization out of list(set(...))... which means we can trim some!

print(list(set(open('/usr/share/dict/words')))[:4])

No module imports needed! Although it's not as pretty as the original post, but neither was Roy's.

-Nick Cash



More information about the Python-list mailing list