Created
February 23, 2010 04:29
-
-
Save jperras/311857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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