[Tutor] how i can change two lists into one directory

bob gailer bgailer at gmail.com
Fri Jul 23 02:15:37 CEST 2010

On 7/22/2010 7:51 PM, ANKUR AGGARWAL wrote:
> hey i have just started making  a app using python and just gt a 
> problem..
> i have two list
> a=["x","z"]
> b=[1,2]
> i want to make a directory like this

Do you mean "dictionary"?

> c={"x":1,"z":2}
> is it possible????

Indeed. There are several ways to do this. Easiest:


> i mean i tried it using loops

d = {}
for i in range(len(a)):
   d[a[i] = b[i]

> and all but i cant append a directory

Of course you can't append, since a dictionary is not a sequence. But 
you can add a key-value pair as the above loop demonstrates.

Bob Gailer
Chapel Hill NC

More information about the Tutor mailing list