Simple list.append() question

Fredrik Lundh effbot at telia.com
Mon Apr 24 12:35:04 EDT 2000


Matthew Hirsch <meh9 at cornell.edu> wrote:
> Hi All,
>
> I have this:
> >>> entire_list=[[]]*3
> >>> entire_list
> [[], [], []]
> >>> entire_list[0].append(1.23)
> >>> entire_list
> [[1.23], [1.23], [1.23]]
>
> I only want to append 1.23 to entire_list[0].  Why did it also append it
> to entire_list[1] and entire_list[2]?

entire_list contains three references to the
same list.

for more info, see:
http://www.python.org/doc/FAQ.html#4.50

</F>





More information about the Python-list mailing list