Advertisement
Guest User

Untitled

a guest
Aug 5th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import sys;
  2.  
  3. input_string = sys.stdin.readline()
  4. input_string = input_string.strip()
  5. input_string = input_string.replace("\n",' ')
  6. input_string = input_string.replace(".",' ')
  7. input_array = input_string.split(" ")
  8. _dict = { }
  9.  
  10. iter = 0
  11. for word in input_array:
  12.     iter += 1
  13.     _lower = word.lower()
  14.     _hash = ''.join(sorted(_lower))
  15.     if not _hash in _dict:
  16.         _dict[_hash] = { 'first':iter,
  17.                          'words':[] }
  18.     if not _lower in _dict[_hash]['words']:
  19.         _dict[_hash]['words'].append(_lower)
  20.  
  21. _array = []
  22. for _hash in _dict:
  23.     if len(_dict[_hash]['words']) > 1:
  24.         _array.append(_dict[_hash]);
  25. _dict = len(_array)
  26. _array = sorted( _array, key=lambda t: t['first'] )
  27. for x in range(0,_dict):
  28.     sys.stdout.write( '\n' + ' '.join( _array[x]['words'] ) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement