day1/exercise/anagrams.py
changeset 395 e886e37a5032
equal deleted inserted replaced
394:b364e40ec828 395:e886e37a5032
       
     1 anag = {}
       
     2 for line in open( 'anag.txt'):
       
     3 	word = line.strip()
       
     4 	key = ''.join(sorted(list(word)))
       
     5 	if key not in anag:
       
     6 		anag[ key ] = [ word ]
       
     7 	else:
       
     8 		anag[key].append(word)
       
     9 for key in anag:
       
    10 	if len(anag[key]) > 1:
       
    11 		print anag[key]
       
    12