From c80b4a34a947e02193faf92a0e554102874ba8ce Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Sat, 1 May 2010 16:16:39 +0530 Subject: Added program anagrams.py. --- day1/exercise/anagrams.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 day1/exercise/anagrams.py diff --git a/day1/exercise/anagrams.py b/day1/exercise/anagrams.py new file mode 100644 index 0000000..28a5b0f --- /dev/null +++ b/day1/exercise/anagrams.py @@ -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 -- cgit