converting tuple to list
Jim Richardson
warlock at eskimo.com
Fri Jan 14 00:23:54 EST 2000
On Thu, 13 Jan 2000 15:14:59 +0100,
Fredrik Lundh, in the persona of <fredrik at pythonware.com>,
brought forth the following words...:
>Adrian Eyre <a.eyre at optichrome.com> wrote:
>> Just out of interest: what is the canonical way of converting a list
>> of tuples to a dictionary? i.e. the opposite of dict.items()
>>
>> [("key1","value1"),("key2","value2")] -> {"key1":"value1","key2":"value2"}
>
>I doubt you can do much better than:
>
>mydict = {}
>for k, v in mylist:
> mydict[k] = v
>
></F>
>
thankyuothankyou this solves a niggling problem I was having _so_
much more elegantly than I had thought of myself, new to python,
and loving every byte...
--
Jim Richardson
Anarchist, pagan and proud of it
WWW.eskimo.com/~warlock
Linux, because life's too short for a buggy OS.
More information about the Python-list
mailing list