T
Tertius
Is there a method to create a dict from a list of keys and a list of
values ?
TIA
Tertius
values ?
TIA
Tertius
{0: 'a', 1: 'b', 2: 'c'}Tertius said:Is there a method to create a dict from a list of keys and a list of
values ?
Peter said:Tertius wrote:
{0: 'a', 1: 'b', 2: 'c'}
Not a method() but a method.
Peter
{0: 'a', 1: 'b', 2: 'c'}
Python 2.3 (#1, Jul 30 2003, 21:59:29)Tertius said:Tertius said: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
{0: 'a', 1: 'b', 2: 'c'}
If I could use the above in Py2.4, it would be even nicer, namely:
- convert itertools to builtins
- add irange(), perhaps as an alias for xrange() like file/open
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.