Python Forum
why does the list of list replicate this way?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why does the list of list replicate this way?
#1


a = [[]] * 10

a
[[], [], [], [], [], [], [], [], [], []]

a[0].append((1,2))

a
[[(1, 2)], [(1, 2)], [(1, 2)], [(1, 2)], [(1, 2)], [(1, 2)], [(1, 2)], [(1, 2)], [(1, 2)], [(1, 2)]]
Why does it replicate the values across the entire list? Bizarre Huh
Reply


Messages In This Thread
why does the list of list replicate this way? - by hshivaraj - Nov-30-2017, 05:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 373 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,287 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,614 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 959 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,924 Oct-26-2022, 04:03 PM
Last Post: deanhystad
Question Keyword to build list from list of objects? pfdjhfuys 3 1,631 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  Replicate Excel operations with Python Lumberjack 3 1,875 May-10-2022, 01:44 AM
Last Post: Lumberjack
  Split a number to list and list sum must be number sunny9495 5 2,369 Apr-28-2022, 09:32 AM
Last Post: Dexty
  How to check if a list is in another list finndude 4 1,885 Jan-17-2022, 05:04 PM
Last Post: bowlofred
  Different out when using conda list and pip list Led_Zeppelin 1 4,118 Jan-14-2022, 09:30 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020