Given two lists and check list, test if for each element in check list, elements occur in similar index in 2 lists.
Input : test_list1 = [2, 6, 9, 7, 8], test_list2 = [2, 7, 9, 4, 8], check_list = [9, 8, 7] Output : False Explanation : 7 is at 4th and 2nd place in both list, hence False. Input : test_list1 = [2, 6, 9, 7, 8], test_list2 = [2, 6, 9, 4, 8], check_list = [9, 8, 6] Output : True Explanation : All from checklist at similar index, hence True.
In this, we iterate for all the elements in list, if elements are different and is present in check list, then False is returned.
OutputThe original list 1 : [2, 6, 9, 7, 8]
The original list 2 : [2, 7, 9, 4, 8]
Are elements at same index for required instances ?: True
In this, we pair like indices using zip() and then all() is used to check for all indices, generator expression is used for iteration logic.
OutputThe original list 1 : [2, 6, 9, 7, 8]
The original list 2 : [2, 7, 9, 4, 8]
Are elements at same index for required instances ?: True
OutputThe original list 1 : [2, 6, 9, 7, 8]
The original list 2 : [2, 7, 9, 4, 8]
Are elements at same index for required instances ?: True