author | Puneeth Chaganti <punchagan@gmail.com> |
Sat, 01 May 2010 16:16:39 +0530 | |
changeset 395 | e886e37a5032 |
parent 394 | b364e40ec828 |
child 396 | 502d4d151fa2 |
--- /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