Best way to convert a list to a dictionary
Remco Gerlich
scarblac-spamtrap at pino.selwerd.nl
Thu May 4 02:21:07 EDT 2000
Michael Husmann wrote in comp.lang.python:
> d = {}
> for k, v in your_list:
> d[k] = v
>
> This example looks nice bus does not work with my Python 1.52. Trying to
> get both elements from 'your_list' produces a TypeError exception:
>
> Traceback (innermost last):
> File "<pyshell#10>", line 1, in ?
> for (k,v) in l:
> TypeError: unpack non-sequence
That means that not all elements of l are tuples or lists as you said.
What does l look like?
--
Remco Gerlich, scarblac at pino.selwerd.nl
"Early to rise, early to bed, makes a man healthy, wealthy and dead." -- TP
More information about the Python-list
mailing list