0

So apparently I am creating a project in which I need to append an element in the "probableX" list however it seems like it is getting appended in the "possibleX" list as well. The said part of my code is the following:

probableX = possibleX
for element in possibleX:
        for possibilityIndex in range(9 - currentX.count(element)):
            print(1, len(possibleX), len(probableX))
            probableX.append(element)
            print(2, len(possibleX), len(probableX))

with the print line I was expecting to get something like:

1 8 8

2 8 9

1 8 9

2 8 10

and so on, however I get:

1 8 8

2 9 9

1 9 9

2 10 10

I could probably fix this by removing the last item of the "possibleX" list manually but I want to understand how is it possible to add something to a list that has not been referenced between print(1) and print(2) lines. Thank you in advance!

Community
  • 1
  • 1
Someone
  • 3
  • 3

1 Answers1

0

Could it be both variables are referencing the same object?

trpl
  • 31
  • 6