Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reinitializing list
#4
(Jul-08-2019, 05:30 PM)Shivesh Wrote: Note : I am not appending anything to my original variables tempPath or allPaths[a][0].

Yes you are. Lists are mutable, so when you assign a variable name to one, you are assigning a pointer to the list. When you do path = tempPath, you are just reassigning that pointer, you are not making an independent copy of the list. To make a copy, you need to do path = tempPath[:] (a full slice of the list). Note that this makes a shallow copy of the list, so any sub-lists in the list will not get copied. But it looks like your lists are all tuples (which are immutable), so that shouldn't be a problem.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Reinitializing list - by Shivesh - Jul-08-2019, 02:42 PM
RE: Reinitializing list - by ichabod801 - Jul-08-2019, 02:50 PM
RE: Reinitializing list - by Shivesh - Jul-08-2019, 05:30 PM
RE: Reinitializing list - by ichabod801 - Jul-08-2019, 05:36 PM
RE: Reinitializing list - by Shivesh - Jul-08-2019, 05:53 PM
RE: Reinitializing list - by ichabod801 - Jul-08-2019, 06:07 PM
RE: Reinitializing list - by Shivesh - Jul-08-2019, 09:42 PM
RE: Reinitializing list - by ichabod801 - Jul-08-2019, 09:50 PM
RE: Reinitializing list - by Shivesh - Jul-08-2019, 10:07 PM

Forum Jump:

User Panel Messages

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