Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lst = [("a", 1), ("b", 2), ("a", 3), ("b", 1), ("a", 2), ("c", 1)]
- dictionary = {}
- for data in lst:
- key = data[0]
- value = data[1]
- if key in dictionary.keys():
- dictionary[key].append(value)
- else:
- dictionary[key] = []
- dictionary[key].append(value)
- print(dictionary)
Add Comment
Please, Sign In to add comment