list to dictionary conversion with multiple values per key?

Solution 1:

from collections import defaultdict

d1 = defaultdict(list)

for k, v in l:
    d1[k].append(v)

d = dict((k, tuple(v)) for k, v in d1.items())

d contains now {1: ('A', 'B'), 2: ('C',)}

d1 is a temporary defaultdict with lists as values, which will be converted to tuples in the last line. This way you are appending to lists and not recreating tuples in the main loop.

Solution 2:

Using lists instead of tuples as dict values:

l = [[1, 'A'], [1, 'B'], [2, 'C']]
d = {}
for key, val in l:
    d.setdefault(key, []).append(val)

print(d)

Using a plain dictionary is often preferable over a defaultdict, in particular if you build it just once and then continue to read from it later in your code:

First, the plain dictionary is faster to build and access.

Second, and more importantly, the later read operations will error out if you try to access a key that doesn't exist, instead of silently creating that key. A plain dictionary lets you explicitly state when you want to create a key-value pair, while the defaultdict always implicitly creates them, on any kind of access.