Sep-01-2020, 04:04 PM
(Aug-31-2020, 08:51 PM)bowlofred Wrote: In your attempt above, if these are really lists then theopponent = pieces
isn't useful because it's just referencing thepieces
list, so any modification will modify both. I'm assuming thatpieces
already exists and that you don't want to change it.
If so, I'd use a comprehension to pull out everything that doesn't match. This doesn't check that there are really only two elements, or thatpiece
is present as one of the elements. But if both are true, it will return the other element.
opponent = [x for x in pieces if x != piece][0]
You got it exactly. That is the answer that I was looking for. Thank you