Please explain why this code

temp=[]
temp1={'a':0,'b':0,'c':0}
for x in range(3):
    temp1['a']=x
    temp1['b']=x
    temp1['c']=x
    temp.append(temp1)
print temp


prints

[{'a': 2, 'c': 2, 'b': 2}, {'a': 2, 'c': 2, 'b': 2}, {'a': 2, 'c': 2, 'b':
2}]

instead of

[{'a': 0, 'c': 0, 'b': 0}, {'a': 1, 'c': 1, 'b': 1}, {'a': 2, 'c': 2, 'b':
2}]

i always did it like this

temp=[]

for x in range(3):
    *temp1={'a':0,'b':0,'c':0}*
    temp1['a']=x
    temp1['b']=x
    temp1['c']=x
    temp.append(temp1)
print temp

this prints it correctly but dont understand the diference


Thank you
António

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to