diff options
author | Puneeth Chaganti | 2010-05-01 16:16:39 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2010-05-01 16:16:39 +0530 |
commit | 8f29d8c89719b8ebf8f6302ed444e621ba1cf92a (patch) | |
tree | f07185d1bbbc4a506d810dbe1b1936e2e316bcc4 | |
parent | 96b0da3def79a46e9eeac4794c52467ea1f359b0 (diff) | |
download | workshops-more-scipy-8f29d8c89719b8ebf8f6302ed444e621ba1cf92a.tar.gz workshops-more-scipy-8f29d8c89719b8ebf8f6302ed444e621ba1cf92a.tar.bz2 workshops-more-scipy-8f29d8c89719b8ebf8f6302ed444e621ba1cf92a.zip |
Added program anagrams.py.
-rw-r--r-- | day1/exercise/anagrams.py | 12 |
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 |