Write a Python program to convert a list of tuples into a dictionary.


Topic: Write a Python program to convert a list of tuples into a dictionary.

Solution

l = [("x", 1), ("x", 2), ("x", 3), ("y", 1), ("y", 2), ("z", 1)]
d = {}
for a, b in l:
    d.setdefault(a, []).append(b)
print (d)



List all Python Programs