Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reinitializing list
#3
Hi @ichabod801,

Even this doesn't solve my issue.
But I guess, problem is not there where you have pointed.

Problem is inside for loop.

By "for loop", I mean line #29 .
Now assume that loop runs for 3 times.

So in its fun run(i.e. i=0), it executes the following statements :
Look at line #33: tempPath = allPaths[a][0]
Here it assigns, tempPath = [(3, 0), (2, 0)] (PS: Look at attached output #line: Current : [(3, 0), (2, 0)])
Then at line #40: path = tempPath; I assign same tempPath to a temporary variable called "path", so that no one can change the
original tempPath or allPaths[a][0] value.
Then at line #52 & #60: path.append(tempP); I appended some values in temporary variable "path".
Now the modified list looks like (Look at attached output #line: Final : [(3, 0), (2, 0), (2, 1), (1, 1), (0, 1)])
Note : I am not appending anything to my original variables tempPath or allPaths[a][0].

Now when the loop iterates for i=2, I get following issues :
At line #33: tempPath = allPaths[a][0]; These are the original list variable, which I have not modified anywhere.
But when I print "tempPath" at line #42 : print("Current : "+str(tempPath)),
Then I get output belonging to temporary variable "path" where I appended some values in previous run of for loop.
Look at the attached output #line : Current : [(3, 0), (2, 0), (2, 1), (1, 1), (0, 1)]
So, "Cuurent" value from current run of loop is same as "Final" value from previous run of loop.

Whereas the expected output should be, "Current" value should always be same and final value should only change.


Guys, please help me solve this issue. I have tried my best to explain the issue.
If you want I can forward my problem statement and program as well. You can run and test at your end.

Thanks in advance.
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