[Tutor] Pouring a list into a dictionary

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Sep 30 00:11:58 EDT 2003



> >Using some of 2.3's new features, we can now say it this way:
> >
> >###
> >dataDict = dict(zip(headers, foundData))
> >###
>
> That even works in 2.2.3. Is this a new concept of backward compatibility?-
> [snip]

Hi Bob,


Very true!  I was confused when I read the docs at:

    http://www.python.org/doc/lib/built-in-funcs.html

For some wacky reason, I thought that:

    dict(zip(('one', 'two'), (2, 3)))

was introduced in 2.3, but that's not right --- we had this in 2.2 too.
Python 2.3 did introduce an improvement to dict(): we can now initialize
it by using keyword arguments:

###
>>> dict(two=2, three=3)
{'three': 3, 'two': 2}
###


Thanks for the correction!




More information about the Tutor mailing list