CBSE Class 11 Computer Science
Question 104 of 104
List Manipulation — Question 18
Back to all questions 18
Question Question 15
Write a program to compare two equal sized lists and print the first index where they differ.
Solution
print("Enter two equal sized lists")
l1 = eval(input("Enter first list: "))
l2 = eval(input("Enter second list: "))
for i in range(len(l1)):
if l1[i] != l2[i]:
print("Lists differ at index", i)
break;
else:
print("Lists are equal")Output
Enter two equal sized lists
Enter first list: [80, 60, 50, 40, 30]
Enter second list: [80, 60, 55, 42, 30]
Lists differ at index 2
=====================================
Enter two equal sized lists
Enter first list: [80, 60, 50, 40, 30]
Enter second list: [80, 60, 50, 40, 30]
Lists are equal