Answer to Question #303094 in Python for rgtd

Question #303094

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


1
Expert's answer
2022-02-27T04:12:22-0500
def excludeitem(item1, item2):
    new_item = []
    max = item1 if len(item1) > len(item2) else item2
    min = item1 if len(item1) < len(item2) else item2
    for i in max:
        if i in min and i not in new_item:
            new_item.append(i)
    return new_item

print(excludeitem([1, 2, 2, 3], [7, 2, 5, 3, 3]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS