Skip to content

Instantly share code, notes, and snippets.

@KamilaBorowska
Created September 7, 2012 17:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save KamilaBorowska/3667795 to your computer and use it in GitHub Desktop.
import os
import random
# Load file and put it to dictionary as set
dictionary = set(word.rstrip(os.linesep) for word in open('unixdict.txt'))
# List of results
results = []
for word in dictionary:
# [::-1] reverses string
reversed_word = word[::-1]
if reversed_word in dictionary and word > reversed_word:
results.append((word, reversed_word))
print(len(results))
for words in random.sample(results, 5):
print(' '.join(words))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment