SHARE
TWEET

rev

a_yadvichuk Apr 23rd, 2019 (edited) 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top