Count items common to both the lists but with different prices | function to count items common to both the lists but with different prices ; for each item of ' list1' check if it is in ' list2' but with a different price ; required count of items ; Driver program to test above
def countItems ( list1 , list2 ) : NEW_LINE INDENT count = 0 NEW_LINE for i in list1 : NEW_LINE INDENT for j in list2 : NEW_LINE INDENT if i [ 0 ] == j [ 0 ] and i [ 1 ] != j [ 1 ] : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT list1 = [ ( " apple " , 60 ) , ( " bread " , 20 ) , ( " wheat " , 50 ) , ( " oil " , 30 ) ] NEW_LINE list2 = [ ( " milk " , 20 ) , ( " bread " , 15 ) , ( " wheat " , 40 ) , ( " apple " , 60 ) ] NEW_LINE print ( " Count ▁ = ▁ " , countItems ( list1 , list2 ) ) NEW_LINE