Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys;
- inputstring = sys.stdin.readline()
- inputstring = inputstring.strip()
- inputstring = inputstring.replace("\n",' ')
- inputstring = inputstring.replace(".",' ')
- inputarray = inputstring.split(" ")
- inputstring = ''
- dictionary = { }
- iterator = 0
- for word in inputarray:
- iterator += 1
- lower = word.lower()
- word_hash = ''.join(sorted(lower))
- if not word_hash in dictionary:
- dictionary[word_hash] = { 'first':iterator,
- 'words':[] }
- if not lower in dictionary[word_hash]['words']:
- dictionary[word_hash]['words'].append(lower)
- anagrams = []
- for word_hash in dictionary:
- if len(dictionary[word_hash]['words']) > 1:
- anagrams.append(dictionary[word_hash]);
- length_of_array = len(anagrams)
- anagrams = sorted( array, key=lambda t: t['first'] )
- for x in range(0,length_of_array):
- print( '\n' + ' '.join( anagrams[x]['words'] ) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement