[Baypiggies] nested list to dict question

Tim Hatch tim at timhatch.com
Tue Dec 28 17:06:01 CET 2010


> I have a nested list which looks something like this:
>
> x = [['104', '4501919'], ['104', '237681091'], ['104', '7669477'],
> ['100528064', '315259111']]

You could try something like this... if you know the identical keys will
always be adjacent there might be another way too.

y = {}
for k, v in x:
    y.setdefault(k, []).append(v)

Tim



More information about the Baypiggies mailing list