I am comparing two lists for common strings and my code currently works to output items in common from two lists.
list1
['5', 'orange', '20', 'apple', '50', 'blender']
list2
['25', 'blender', '20', 'pear', '40', 'spatula']
Here is my code so far:
for item1 in list1[1::2]:
for item2 in list2[1::2]:
if item1 == item2:
print(item1)
This code would return blender. What I want to do now is to also print the number before the blender in each list to obtain an output similar to:
blender, 50, 25
I have tried to add two new lines to the for loop but did not have the desired output:
for item1 in list1[1::2]:
for item2 in list2[1::2]:
for num1 in list1[0::2]:
for num2 in list2[0::2]:
if item1 == item2:
print(item1, num1, num2)
I know now that making for loops is not the answer. Also trying to call item1[-1] does not work. I am new to Python and need some help with this!
Thank you