muhammad_nasif

Untitled

Apr 13th, 2021 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. lst = [("a", 1), ("b", 2), ("a", 3), ("b", 1), ("a", 2), ("c", 1)]
  2.  
  3. dictionary = {}
  4.  
  5. for data in lst:
  6. key = data[0]
  7. value = data[1]
  8. if key in dictionary.keys():
  9. dictionary[key].append(value)
  10. else:
  11. dictionary[key] = []
  12. dictionary[key].append(value)
  13.  
  14. print(dictionary)
  15.  
Add Comment
Please, Sign In to add comment