# HG changeset patch # User Puneeth Chaganti # Date 1272710799 -19800 # Node ID e886e37a5032d9a0309767f44ca459c0554ee29b # Parent b364e40ec828a910990e4a68e30805137c5a4a9c Added program anagrams.py. diff -r b364e40ec828 -r e886e37a5032 day1/exercise/anagrams.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/day1/exercise/anagrams.py Sat May 01 16:16:39 2010 +0530 @@ -0,0 +1,12 @@ +anag = {} +for line in open( 'anag.txt'): + word = line.strip() + key = ''.join(sorted(list(word))) + if key not in anag: + anag[ key ] = [ word ] + else: + anag[key].append(word) +for key in anag: + if len(anag[key]) > 1: + print anag[key] + \ No newline at end of file