Anagrams: Difference between revisions

Content added Content deleted
(→‎{{header|J}}: shorter solution)
(→‎{{header|Python}}: Anagram not acronym.)
Line 26: Line 26:
>>> len(words)
>>> len(words)
25104
25104
>>> acronym = defaultdict(list) # map sorted chars to acronyms
>>> anagram = defaultdict(list) # map sorted chars to anagrams
>>> for word in words:
>>> for word in words:
acronym[str(sorted(word))].append( word )
anagram[str(sorted(word))].append( word )


>>> count, max_acronyms = max((len(acr), acr) for acr in acronym.itervalues())
>>> count, max_anagrams = max((len(ana), ana) for ana in anagram.itervalues())
>>> for acr in acronym.itervalues():
>>> for ana in anagram.itervalues():
if len(acr) >= count:
if len(ana) >= count:
print acr
print ana