opposite of dict.items()

Berthold Hoellmann bhoel at web.de
Fri Aug 29 18:03:12 CEST 2003


Tertius <tcronj at ananzi.co.za> writes:

> Tertius wrote:
>> Is there a method to create a dict from a list of keys and a list of
>> values ?
>> TIA
>> Tertius
>>
>
> I found a way...
>
> a = {}
> for k , v in zip(keys,values):
> 	a[k] = v
>

Or:

>python
Python 2.3 (#1, Jul 30 2003, 21:59:29) 
[GCC 3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=(1,2,3)
>>> b=(4,5,6)
>>> dict(zip(a,b))
{1: 4, 2: 5, 3: 6}
>>> 

Greetings
Berthold
-- 
bhoel at web.de / http://starship.python.net/crew/bhoel/
        It is unlawful to use this email address for unsolicited ads
        (USC Title 47 Sec.227). I will assess a US$500 charge for
        reviewing and deleting each unsolicited ad.




More information about the Python-list mailing list