Python Forum
Why does this list of lists end up with the same values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why does this list of lists end up with the same values
#1
How can this be explained?
x = [[]]*3
x[0].append('a')
print(x)
>>> returns [['a'], ['a'], ['a']]
Reply


Messages In This Thread
Why does this list of lists end up with the same values - by alehak - Jul-18-2019, 11:00 AM
RE: Append working - by stranac - Jul-18-2019, 11:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using Lists as Dictionary Values bfallert 3 86 5 hours ago
Last Post: buran
  Copying the order of another list with identical values gohanhango 7 1,136 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,218 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Comparing List values to get indexes Edward_ 7 1,154 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 915 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Adding values with reduce() function from the list of tuples kinimod 10 2,637 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,065 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  returning a List of Lists nafshar 3 1,060 Oct-28-2022, 06:28 PM
Last Post: deanhystad
  Creating list of lists, with objects from lists sgrinderud 7 1,614 Oct-01-2022, 07:15 PM
Last Post: Skaperen
  AttributeError: 'list' object has no attribute 'values' ilknurg 4 14,953 Jan-19-2022, 08:33 AM
Last Post: menator01

Forum Jump:

User Panel Messages

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