Guest User

Rhymes ? with : Perl

a guest
Jan 26th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import re
  2. c = re.compile(r"(.*[ea]?[ui]?rl$)")
  3. n = open("/usr/share/dict/words")
  4. z = n.read().split("\n")[:-1]
  5. n.close()
  6. del n
  7. for i in range(len(z)):
  8.     f = z[i]
  9.     if re.match(c, f):
  10.         print("{} probably rhymes with Perl".format(f))
  11.  
  12.     if f == f[::-1] and len(f) > 1:
  13.         print("{} is a palindrome".format(f))
  14.  
  15. #    real    0m32.942s
  16. #    user    0m32.060s
  17. #    sys     0m0.620s
  18.  
  19. #    avg     .32942s / loop
Advertisement
Add Comment
Please, Sign In to add comment