Skip to content
Advertisement

Write a python code to merge two list with the following condition [closed]

If two list is having same number, then the final list should not have the number

Advertisement

Answer

Check this code:

ls=[1,2,3,4,5,5]
ls1=[1,2,3,4,5,7,8,9]

common_elements=set(ls).intersection(set(ls1))

for i in common_elements:
    if ls.__contains__(i):
       ls.remove(i)
    if ls1.__contains__(i):
       ls1.remove(i)
       
final_ls=ls+ls1
print(final_ls)
Advertisement