comparison python/anagram.py @ 21:099a3bfa2852

fixes to anagram.py
author k0s <k0scist@gmail.com>
date Fri, 26 Feb 2010 13:19:14 -0500
parents f3ab51c79813
children 4096771c8b9f
comparison
equal deleted inserted replaced
20:03fc1f76db91 21:099a3bfa2852
43 43
44 sublist = [ i for i in wordlist[index:] 44 sublist = [ i for i in wordlist[index:]
45 if is_in(i, subword) is not None ] 45 if is_in(i, subword) is not None ]
46 subgram = anagramize(subword, sublist, level+1) 46 subgram = anagramize(subword, sublist, level+1)
47 47
48 # import pdb; pdb.set_trace()
49 if subgram is not None: 48 if subgram is not None:
50 anagrams += [ ' '.join((word, i)) for i in subgram ] 49 anagrams += [ ' '.join((word, i)) for i in subgram ]
51 50
52 if 0: 51 if 0:
53 print '%s%s returning %s' % ('-' * level, theword, anagrams) 52 print '%s%s returning %s' % ('-' * level, theword, anagrams)
85 sys.exit(0) 84 sys.exit(0)
86 85
87 f = file(options.filename, 'r') 86 f = file(options.filename, 'r')
88 read_dictionary(f) 87 read_dictionary(f)
89 88
89 # XXX could cleanup
90 anagram = ' '.join(args) 90 anagram = ' '.join(args)
91
92 print anagram
93 print '-' * len(anagram)
94
95 anagram = ''.join(anagram.split()).lower() 91 anagram = ''.join(anagram.split()).lower()
96 92
97 # don't use letter names 93 # don't use letter names
98 dictionary = [ i for i in dictionary if (len(i) > 1) or i in 'ai' ] 94 dictionary = [ i for i in dictionary if (len(i) > 1) or i in 'ai' ]
99 95