# HG changeset patch # User Jeff Hammel # Date 1644600818 28800 # Node ID 83618049c2ffc63a69d27157f810a06bb15352a6 # Parent 8d3df8c0c730e365dc621629e53ab10cefe5ddd3 py3 diff -r 8d3df8c0c730 -r 83618049c2ff python/anagram.py --- a/python/anagram.py Fri Aug 13 15:16:21 2021 -0700 +++ b/python/anagram.py Fri Feb 11 09:33:38 2022 -0800 @@ -25,7 +25,7 @@ def anagramize(theword, wordlist, level=0): if 0: - print '%s%s : %s' % ('-' * level, theword, wordlist) + print('%s%s : %s' % ('-' * level, theword, wordlist)) anagrams = [] @@ -49,12 +49,12 @@ anagrams += [ ' '.join((word, i)) for i in subgram ] if 0: - print '%s%s returning %s' % ('-' * level, theword, anagrams) + print('%s%s returning %s' % ('-' * level, theword, anagrams)) if anagrams: return anagrams return None - + if __name__ == '__main__': import sys from optparse import OptionParser @@ -75,16 +75,16 @@ options.filename = i break else: - print 'Dictionary not found' + print('Dictionary not found') parser.print_help() sys.exit(1) if not args: - print 'please provide an anagram' + print('please provide an anagram') sys.exit(0) - f = file(options.filename, 'r') - read_dictionary(f) + with open(options.filename, 'r') as f: + read_dictionary(f) # XXX could cleanup anagram = ' '.join(args) @@ -95,8 +95,8 @@ wordlist = [ i for i in dictionary if i and is_in(i, anagram) is not None ] - + anagrams = anagramize(anagram, wordlist) if anagrams: - print '\n'.join(anagrams) + print('\n'.join(anagrams))