[Tutor] making list into a dictionary

Liam Clarke cyresse at gmail.com
Fri Nov 5 05:28:40 CET 2004


Hey Kumar, 

I'd go - 

c={}
for item in range(len(a)):
 	c[b[item]]=a[item]

But there is no doubt a simpler way.

Good luck,

Liam Clarke
On Thu, 4 Nov 2004 20:18:45 -0800 (PST), kumar s <ps_python at yahoo.com> wrote:
> Dear group,
>  I want to convert 2 lists into a dictionary object.
> 
> Can I do that using list comprehension or by any other
> method:
> 
> a = ['apple', 'carrot', 'egg', 'cicken']
> b = ['fruit', 'vegie', 'poultry', 'meat']
> 
> c = {}
> 
> I want to create:
> c = {'fruit':'apple',
> 'vegie':'carrot',
> 'poultry':'egg',
> 'mean':'chicken'}
> 
> Could any one help, please.
> 
> Thanks
> Kumar.
> 
> __________________________________
> Do you Yahoo!?
> Check out the new Yahoo! Front Page.
> www.yahoo.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list