-1

In the code here:

movexy = posgrid[tileclicked1] #
while movexy[x] > tempxy[x]:
    print movexy
    print posgrid[tileclicked1]

    movexy[x] -= 1

Where the value of posgrid[tileclicked1] = [75, 120] And the variable x = 0

I've encountered the problem that when I subtract one from movexy[x], one is also automatically subtracted from the list from which it got it's value, posgrid... How come? I create the movexy list only in order to have the posgrid list remain unchanged. Why does this happen?

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253

1 Answers1

1

Here, you are not creating a new list. Both are pointing to the same list.

You can copy list in different ways.For example,

New_list = old_list[:]
Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57