Dictionary and List

sorot at my-deja.com sorot at my-deja.com
Fri Oct 22 06:52:45 EDT 1999


I'm using python 1.5.1. While i'm writing the part of python script
like this

## Part of script ##
my_list = []
my_dict = {'a':'','b':[]}
x = ['a','b','c','d']
for i in range(0,len(x)):
   my_dict['a'] = x[i]
   my_list.append(my_dict)

print my_list
## end ##

The out put should be like
my_list = [{'a':'a','b':[]},{'a':'b','b':[]},{'a':'c','b':[]},
{'a':'d','b':[]}]

But i got output
my_list = [{'a':'d','b':[]},{'a':'d','b':[]},{'a':'d','b':[]},
{'a':'d','b':[]}]

Or did i program anything wrong?

Thanks in advance,
Sorot P.


Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list