<div class="gmail_quote">On Fri, Nov 6, 2009 at 08:15, lee <span dir="ltr"><<a href="mailto:san82moon@gmail.com">san82moon@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
hi,<br>
<br>
rfids= ['01','02']<br>
i = 01<br>
row = {}<br>
items = []<br>
for rfid in rfids:<br>
<br>
brains = ['1','2']<br>
<br>
if brains:<br>
for brain in brains:<br>
# this loop must run only once for each value of i<br>
row['itemnos'] = 'item_0'+str(i)+'s'<br>
print 'hi'<br>
items.append(row)<br>
print items<br>
break<br>
i=i+1<br>
<br>
the above code produces output a:<br>
[{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}]<br>
but i want it to be,<br>
[{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}]<br>
<br>
can anyone point wer am erroring.<br>
Thanks in advance.<font color="#888888"></font><br></blockquote><div><br>Your call to items.append(row) passes row by reference. You added a row
dictionary with key "itemnos" set to value "item_01s" the first time
through the loop. The second time, you added a row dictionary with key
"itemnos" set to value "item_02s". This modified the underlying `row`
dictionary, so it also modified what you thought you put in the list in
the first time through the loop. <br></div></div>