Q. Write a program to compare two equal sized lists and print the first index where they differ.

 


You can understand by Watching video :-



Answer = 

 

lst1 = eval(input("Enter first list :-"))
lst2 = eval(input("Enter second list :-"))
for i in range(len(lst1)):
      if lst1[i]  != lst2[i] :
            print("index = ",i)
            break



Output :- 

Enter first list :-[1,2,3,4,5,6,7,8,9]
Enter second list :-[1,3,2,4,5,6,7,8,9]
index =  1

>>>


2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Sir at last we have to add a break know sir because in the question it is asked to print the first index where they aren't equal

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post