Skip to content

Instantly share code, notes, and snippets.

@jperras
Created February 23, 2010 04:29
Show Gist options
  • Save jperras/311857 to your computer and use it in GitHub Desktop.
Save jperras/311857 to your computer and use it in GitHub Desktop.
import redis
def encode(word):
return word.encode('rot13')
def cleanup():
db.delete('eng')
db.delete('eng-rot13')
if __name__ == "__main__":
count = 0
db = redis.Redis()
cleanup()
for line in open('/usr/share/dict/words', 'r'):
count += 1
db.sadd('eng', line)
db.sadd('eng-rot13', encode(line))
if (count % 10000 == 0):
print "Loaded %d words so far" % count
db.sinterstore('eng-intersect', 'eng', 'eng-rot13')
msg = "English dictionary contains %d words, and %d rot13'ed words"
print msg % (db.scard('eng'), db.scard('eng-rot13'))
print "Cardinality of intersection: %d " % db.scard('eng-intersect')
cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment