author | Christopher Burns <chris.d.burns@gmail.com> |
Tue, 29 Jun 2010 00:59:26 -0500 | |
branch | scipy2010 |
changeset 432 | 13e5d0e2cd40 |
parent 395 | e886e37a5032 |
permissions | -rw-r--r-- |
395
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
1 |
anag = {} |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
2 |
for line in open( 'anag.txt'): |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
3 |
word = line.strip() |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
4 |
key = ''.join(sorted(list(word))) |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
5 |
if key not in anag: |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
6 |
anag[ key ] = [ word ] |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
7 |
else: |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
8 |
anag[key].append(word) |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
9 |
for key in anag: |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
10 |
if len(anag[key]) > 1: |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
11 |
print anag[key] |
e886e37a5032
Added program anagrams.py.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff
changeset
|
12 |