| | |
List Problem
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
I've got an issue with lists right now. I've got 2 lists, Checker1 and Checker2, which check for the Ko rule in my game of Go. However, Checker2 should always be checking the board one turn behind Checker1, which checks the board every turn. That way, the Ko rule can be caught and dealt with. To do that, I have a Temp list which gets the contents of Checker1 before each run-through, and set it's contents to Checker2. Then the piece is added to the board. Checker1 gets the contents of the board, and Checker1 and Checker2 are compared to check for the Ko rule.
However, my problem is that for some reason, whenever Checker1 gets the contents of the board, Checker2's contents change to Checker1's contents (I've tested it through printing the 2 lists). Is there any particular reason why? I made copies of all of the lists doing
But the lists are still having their contents shared. Any idea why this is?
However, my problem is that for some reason, whenever Checker1 gets the contents of the board, Checker2's contents change to Checker1's contents (I've tested it through printing the 2 lists). Is there any particular reason why? I made copies of all of the lists doing
Python Syntax (Toggle Plain Text)
list1 = list2[:]
But the lists are still having their contents shared. Any idea why this is?
Last edited by Azurea; May 14th, 2008 at 6:38 pm.
there must be something else going on. When you make a copy of a list
Are you sure your not doing something else incorrect? If you can, post the section of your code were the checker lists are used and changed etc then someone might be able to see if anything else is happening
list2 = list1[:] it fills list2 with list1's values, but when you change either list1 or list2, the change isn't mirrored so list1 would stay the same if list2 was changed.Are you sure your not doing something else incorrect? If you can, post the section of your code were the checker lists are used and changed etc then someone might be able to see if anything else is happening
•
•
Join Date: Dec 2006
Posts: 1,056
Reputation:
Solved Threads: 298
If you are not changing the contents of one or both of the lists, then use a tuple instead:
Python Syntax (Toggle Plain Text)
tuple1 = tuple(list2)
![]() |
Similar Threads
- Back button problem with $Sessions and GET (PHP)
- linked list problem!!! (C)
- Linked List problem (C)
- struct linked list problem (C)
- Weird (?) problem using std::list ... (C++)
- The C++ LINKED LIST (C++)
- remove method linked list (C)
- Linked List & Objects (C++)
- help finding and solving a problem (C++)
Other Threads in the Python Forum
- Previous Thread: Question with for loop
- Next Thread: help...i want to call a f'n that returns a string...
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied apache application argv beginner book change code color converter dictionary dynamic edit editing enter examples excel file filename float format ftp function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric output parameters parsing path phonebook port prime program programming projects py2exe pygame pyopengl pyqt python random recursion recursive redirect remote reverse scrolledtext server session simple smtp software sprite ssh statictext string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






