Creating dict from keys and values

Just just at xs4all.nl
Sun May 29 05:08:36 EDT 2005


In article <d7c0d5$nv0$1 at star.cs.vu.nl>,
 Dirkjan Ochtman <dochtman at cs.vu.nl> wrote:

> Hi there,
> 
> I'm looking for an intuitive way of creating a dict from what the 
> dict.keys() and dict.values() will return (two lists).
> 
> Currently, I'm using this code:
> 
> > d = {}
> > for i in range(len(data)):
> > 	d[header[i]] = data[i]
> 
> But this feels kind of inelegant. So: is there a better way?

   d = dict(zip(header, data))

Just



More information about the Python-list mailing list