Define a function named "excludeItem" which take two parameters (item1 & item2) and both
are list. This function will create a separate list named "result" which only include items found
in both lists. The result list should not have duplicate value.
For example, given item1 = [1,2,3,4,2,1] while item2 = [2, 4, 4, 2]. This function will return a
result of [2,4]. Note that the output value is unique (no duplicate). The function must be able
to accept other parameters as well i.e. list of strings or mixture of strings and digits
def excludeitem(item1, item2):
result = []
for i in item1:
if i in item2 and i not in result:
result.append(i)
return result
print(excludeitem([2,4,4,2], [1,2,3,4,2,1]))
Comments
Leave a comment