Code golf challenge: XKCD 936 passwords

Roy Smith roy at panix.com
Tue Oct 8 21:38:12 EDT 2013


On Monday, October 7, 2013 8:17:21 PM UTC-10, Chris Angelico wrote:

> > print(*__import__("random").sample(open("/usr/share/dict/words").read().spli
> > t("\n"),4))


In article <68365e43-498f-4ad2-bac3-6a02938159c7 at googlegroups.com>,
 sprucebondera at gmail.com wrote:

> import random as r
> print(*r.sample(open("/usr/share/dict/words").readlines(),4)) 
> 
> Shaves off 6 characters.


If you're willing to accept a sub-optimal random number generator:

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

I'll also point out that on my OSX box, I could have used 
/usr/share/dict/web2 and saved one more character :-)
¯



More information about the Python-list mailing list