-1

Suppose I have 2 lists

a = [5, 8, 1, 3, 4]
b = [6, 9, 2, 4, 5]

I want to compare element in index 0 in list a and element in index 0 in list b, and for example, if a > b add true to a list, and then compare index 1 a and index 1 b. And like before if a > b add true to a list, else add false to the same list.

I tried using for loop but for loop compare element from index 0 a with index 0 - 4 with b and not just comparing the same element. How do I compare the same index?

JayBirds
  • 1
  • 2
  • Does this answer your question? [Comparing two lists element-wise in python](https://stackoverflow.com/questions/55986094/comparing-two-lists-element-wise-in-python) – ThePyGuy Mar 29 '21 at 04:50

1 Answers1

-1

Try this

a = [5, 8, 1, 3, 4]
b = [6, 9, 2, 4, 5]
result = []

for i, j in zip(a,b):
    if i > j:
        result.append('True')
    else:
        result.append('False')

print (result)  
Neal Titus Thomas
  • 483
  • 1
  • 6
  • 16