Answer to Question #295969 in Python for Michael

Question #295969

You have given A and B as two lists with may have repeated element in the respective list. Write a python function Merge_List(A, B) which take list A and B as input and return a merged list. The function will merge the list B with A (means the list A will be expanded) such that the resultant A still contain no duplicates.

 

Example-1

Example-2

Example-3

Input:

A:

 1

 2

 3

 4

 5

 

B:

 1

 1

 1

 11

 2

 3

Output:

[1, 2, 3, 4, 5, 11]

Input:

A:

 1

 2

 3

 4

 5

 

B:

1

2

3

4

5

 

Output:

[1, 2, 3, 4, 5]

Input:

A:

 1

 2

 3

 

B:

4

5

 

Output:

[1, 2, 3, 4, 5]



1
Expert's answer
2022-02-10T15:27:01-0500
def merge(A,B):
    temp = set(A)
    for item in B:
        temp.add(item)
    return temp


A = [1,2,3,4,5]
B = [1,2,3,4,5]


print(merge(A,B))

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