newbie question - python lists
Jon Clements
joncle at googlemail.com
Fri Nov 6 10:17:24 EST 2009
On Nov 6, 2:15 pm, lee <san82m... at gmail.com> wrote:
> hi,
>
> rfids= ['01','02']
> i = 01
> row = {}
> items = []
> for rfid in rfids:
>
> brains = ['1','2']
>
> if brains:
> for brain in brains:
> # this loop must run only once for each value of i
> row['itemnos'] = 'item_0'+str(i)+'s'
> print 'hi'
> items.append(row)
> print items
> break
> i=i+1
>
> the above code produces output a:
> [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}]
> but i want it to be,
> [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}]
>
> can anyone point wer am erroring.
> Thanks in advance.
You've made a good effort (and discovered at least one major common
gotcha).
There's lots in your code that needs highlighting. However, probably a
good starting point would to be describe in plain english, what you're
trying to achieve; Are you really sure you want a list of single item
dict's?
Jon.
More information about the Python-list
mailing list