First commit of partial RosettaCode contents.
Pushing this for testing purposes. Lots of work still needed.
This commit is contained in:
commit
1e05ecd7ee
781 changed files with 9080 additions and 0 deletions
25
Task/Anagrams/Python/anagrams-3.py
Normal file
25
Task/Anagrams/Python/anagrams-3.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
>>> import urllib
|
||||
>>> from collections import defaultdict
|
||||
>>> words = urllib.urlopen('http://www.puzzlers.org/pub/wordlists/unixdict.txt').read().split()
|
||||
>>> len(words)
|
||||
25104
|
||||
>>> anagram = defaultdict(list) # map sorted chars to anagrams
|
||||
>>> for word in words:
|
||||
anagram[tuple(sorted(word))].append( word )
|
||||
|
||||
|
||||
>>> count = max(len(ana) for ana in anagram.itervalues())
|
||||
>>> for ana in anagram.itervalues():
|
||||
if len(ana) >= count:
|
||||
print ana
|
||||
|
||||
|
||||
['angel', 'angle', 'galen', 'glean', 'lange']
|
||||
['alger', 'glare', 'lager', 'large', 'regal']
|
||||
['caret', 'carte', 'cater', 'crate', 'trace']
|
||||
['evil', 'levi', 'live', 'veil', 'vile']
|
||||
['elan', 'lane', 'lean', 'lena', 'neal']
|
||||
['abel', 'able', 'bale', 'bela', 'elba']
|
||||
>>> count
|
||||
5
|
||||
>>>
|
||||
Loading…
Add table
Add a link
Reference in a new issue