summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPuneeth Chaganti2010-05-01 16:16:39 +0530
committerPuneeth Chaganti2010-05-01 16:16:39 +0530
commitc80b4a34a947e02193faf92a0e554102874ba8ce (patch)
treef07185d1bbbc4a506d810dbe1b1936e2e316bcc4
parent38f395a530e630b094fc517d080b41b5a7054f00 (diff)
downloadworkshops-c80b4a34a947e02193faf92a0e554102874ba8ce.tar.gz
workshops-c80b4a34a947e02193faf92a0e554102874ba8ce.tar.bz2
workshops-c80b4a34a947e02193faf92a0e554102874ba8ce.zip
Added program anagrams.py.
-rw-r--r--day1/exercise/anagrams.py12
1 files changed, 12 insertions, 0 deletions
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