Advertisement
a_yadvichuk

rev

Apr 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. f = open('input.txt')
  2. d = {}
  3. for line in f:
  4.     words  = line.strip().split(' - ')
  5.     key = words[0]
  6.     val = words [1].split(',')
  7.     for k in val:
  8.         if k in d:
  9.             d[k].append(key)
  10.         else:
  11.             d[k] = [key]
  12. f.close()
  13. for k in d:
  14.     d[k].sort()
  15. g = open('output.txt', 'w')
  16. g.write(str(len(d)) + '\n')
  17. for val in sorted(d):
  18.     g.write(val + ' - ' + ', '.join(d[val]) + '\n')
  19.  
  20. g.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement