Bad_Programist

Untitled

Dec 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. N = int(input())
  2. D = {}
  3. S = {}
  4. for i in range(N):
  5.     va = []
  6.     key, *val = input().split()
  7.     val.remove('-')
  8.     for j in val:
  9.         va.append(j.strip(','))
  10.     D[key] = va
  11. for key in D:
  12.     for i in D[key]:
  13.         if i in S:
  14.             S[i].append(key)
  15.         else: S[i] = [key]
  16. for i in S:
  17.     S[i] = sorted(S[i])
  18. print(len(S))
  19. for i in sorted(S):
  20.     print(i + ' - ' + ', '.join(S[i]))
Advertisement
Add Comment
Please, Sign In to add comment