Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created January 22, 2011 03:45
Show Gist options
  • Save seungjin/790836 to your computer and use it in GitHub Desktop.
Save seungjin/790836 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib2, re
processed_list = []
cond = [('w','m'),('u','n'),('p','d'),('g','b'),('b','q')]
for word in filter(lambda x: x != None, map(lambda x: len(x.rstrip().lstrip().lower()) > 0 and x.rstrip().lstrip().lower() or None , urllib2.urlopen('http://www.u.arizona.edu:80/~echan3/539/english-vocab.txt').read().split('\r\n'))):
if re.match('^[xolswmunpdbgqz]*$',word) :
w = list(word)
for i in range(0,len(w)):
for j in cond:
if j[0] == list(word)[i]: w[i] = j[1]
if j[1] == list(word)[i]: w[i] = j[0]
k = "".join(w)
if re.match('[aeiou]*',k[::-1]) :
word2 = k[::-1]
processed_list.append(tuple([word,word2]))
processed_list.sort(lambda x,y: cmp(len(x[1]),len(y[1])))
processed_list.reverse()
# Solve the question a)
print "Answer for question 1:"
for i in processed_list[:20]: print "\t"+i[1]
# Solve the question b)
print "Answer for question 2:"
for i in processed_list:
if i[0] == i[1]: print "\t"+i[1]; break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment