0
How can i check list on python
This is my example and I want to check list like this. List1= [‘a’,’b’,’c’] List2= [‘a’,’b’,’c’] count=0 I want to check my list like this List1=[‘a’]==list2=[‘a’] if false count=count+1 and do it again list1=[‘b’]==list2=[‘b’] until the end of list1 Thank you for help
2 Answers
+ 2
There are several ways you could structure a loop in Python to accomplish this. Here's an example of 1.
count = 0
for i in range(len(list1)):
if list1[i] != list2[i]:
# increment count when
# elements don't match
count += 1
else:
... # code when they do match
You can change the comparison operator to == to flip the if statement around etc. This loop, of course, assumes that list1 and list2 have the same length.
+ 1
Thank you very much