Answer to Question #296107 in Python for Rahul

Question #296107

You have given A and B as2 lists which may have repeated elements in respective list. Write a python function mg-L(A,B) which takes list A and B as input and returns 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. Specify input in fixed form. Use only list operations. For example if


A =[2,4,8,2,1] and B=[10,4,3,8,7] merged-list =[1,2,3,4,7,8,10]

1
Expert's answer
2022-02-10T09:49:13-0500
def merge(A, B):
	merged = []
	for el in A + B:
		if el not in merged:
			merged.append(el)
	merged.sort()
	return merged

A = [2,4,8,2,1]
B = [10,4,3,8,7]
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