[Tutor] Pouring a list into a dictionary

Bob Gailer bgailer at alum.rpi.edu
Mon Sep 29 21:13:39 EDT 2003


At 05:40 PM 9/29/2003, Danny Yoo wrote:



>On Mon, 29 Sep 2003, Allen wrote:
>
> > The answer to my last inquiry worked out to be this: (thanks for the
> > suggestions)
> >
> > I have two lists (same length) and needed field ONE from list A
> > (headings) be the key to the value of field ONE of list B (foundData).
> > Iterate through these to create my dictionary.
> >
> > dataDict={}
> > for k, v in map(None, headings, foundData):
> >    dataDict[k]= v
>
>Hi Allen,
>
>
>Ah!  As of Python 2.3, there's another concise way of saying this:
>
>###
>dataDict={}
>for k, v in map(None, headings, foundData):
>    dataDict[k]= v
>###
>
>
>
>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]

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003


More information about the Tutor mailing list