Question: Problem 2 Create a function called intersection that returns the intersection of two lists. The intersection of two lists is simply the common elements shared
Problem 2 Create a function called intersection that returns the intersection of two lists. The intersection of two lists is simply the common elements shared by both. As in Problem 1, you will probably use for loop(s). Please refer to Homework #2 if you forget how to iterate over lists.
This code is returning "unexpected EOF while parsing"
def intersection(list_a, list_b):
# ** your solution here **
res = []
for x in list_a:
if (not x in res) and (x in list_b):
for i in range(min(list_a.count(x), list_b.count(x))):
res.append(x)
return output_list
if __name__ == '__main__':
# do not write anything here (the instructor will use this space to test
# your function)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
