(Aug-31-2020, 07:48 PM)bowlofred Wrote: I would probably just shuffle the list, then use the first one as my piece and the second as the opponent.
import random
pieces = ["X", "O"]
pieces = random.shuffle(pieces)
# my piece is always pieces[0] and my opponent is pieces[1]
If you really prefer to use separate variables for each piece (and I think there are reasons you shouldn't) then you could just sample the list like this...
import random
pieces = ["X", "O"]
piece, opponent = random.sample(pieces, k=2)
What I provided was just a simple working example. I need to be able to have one item of a list in a variable and use that yo put the other into a separate variable.
I cannot select them both at first as one item may be compared to many lists to select its counterpart from many list pairs.
opponent = pieces
opponent.remove(piece)
opponent = opponent[0]
Optomizing these 3 lines is my goal
(Aug-31-2020, 06:44 PM)deanhystad Wrote: What do you want to do, remove the piece from the existing list or get a new list that is the same as the existing but with the piece removed?
Not quite either. I have a list with two items and I have a variable containing one of those two items. I want to use the list and the variable to put the other item into a third variable.
Using a list and a variable containing one item in the list, I need to be able to store the other item in the list to a new variable.