newbie question - python lists

lee san82moon at gmail.com
Fri Nov 6 17:47:33 CET 2009


On Nov 6, 7:48 pm, Jim <jim.heffe... at gmail.com> wrote:
> On Nov 6, 9:15 am, lee <san82m... at gmail.com> wrote:
>
> > can anyone point wer am erroring.
>
> I'm not sure what you are trying to do, but it is odd, isn't it, that
> you never refer to brain in the "for brain in brains:" loop?  I think
> you are mixing i and brain somehow.
>
> Jim

ok let me make it clear,

brains = ['1','2']
for brain in brains:
    row['item'] = brain
    items.append(row)
    print items

This produces
[{'item': '1'}]
[{'item': '2'}, {'item': '2'}]
but i want
[{'item': '1'}]
[{'item': '1'}, {'item': '2'}]

if i do items.append(brain), it gives,
['1', '2']
but i want dictionary inside list.
@Jon - Yes i want single item dict's
@Robert - i use python 2.4 .

Thanks
Lee.



More information about the Python-list mailing list