Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys
  5. from collections import defaultdict
  6.  
  7. inverted_index = defaultdict(set)
  8.  
  9. def reduce(kv):
  10. word, filename = kv.split('\t')
  11. inverted_index[word].add(filename.strip())
  12.  
  13. if __name__ == "__main__":
  14. for kv in sys.stdin:
  15. reduce(kv)
  16.  
  17. for word, filename in inverted_index.items():
  18. print('{0}\t{1}'.format(word, filename))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement