Code golf challenge: XKCD 936 passwords

random832 at fastmail.us random832 at fastmail.us
Tue Oct 8 11:47:56 EDT 2013


On Tue, Oct 8, 2013, at 2:45, sprucebondera at gmail.com wrote:
> On Monday, October 7, 2013 8:17:21 PM UTC-10, Chris Angelico wrote:
> > print(*__import__("random").sample(open("/usr/share/dict/words").read().split("\n"),4)) # 87
> 
> import random as r
> print(*r.sample(open("/usr/share/dict/words").readlines(),4)) # 80

How about this? My version is also portable to systems with different
file locations, and localizable to different language dictionaries (Some
assembly required).

import sys,random
print(*map(str.strip,random.sample(list(sys.stdin),4))) # 73

Importing random as r doesn't actually save anything, since " as r" is
the same five characters you saved from the one use of it.



More information about the Python-list mailing list