Working in Python 2.7.
I have two different lists, A and B (simplified to make explanations more clear).
A = [1, 2, 4, 3, 5]
B = [2, 0, 3, 2, 1]
I would like to be able to compare the positional values of each list ex- A[1] v B[1]- and total up the instances in which A is larger (A “wins”), the instances when the two values are the same (A “ties”), and the instances when B is larger (A “losses”).
To make things a little more complicated I’m also using random.shuffle() to randomize the order of the list every time through a for loop.
I first tried using:
def listComp(listA, listB):
Awins = 0
Aties = 0
Alosses = 0
for i in range(0, whatever):
random.shuffle(listA)
random.shuffle(listB)
if A[0] > B[0]:
Awins += 1
elif A[0] == B[0]:
Aties += 1
elif A[0] < B[0}:
Alosses += 1
And then in each of the if statements, coding additional if statements to account for all the possible variations. Obviously, this gets very labor-intensive as the size of the list grows. There’s got to be an easier way, right?
Sounds like you want
zip: