Akansha Yadav shows how to merge two Python lists by converting them to sets and using the union operator (|). With lists [1, 2, 3] and [3, 4, 5], the function returns [1, 2, 3, 4, 5], removing duplicates in one line.
Chapters
Let's write a Python program to find the union from the two given lists. So here I am on Replit creating a function unified, and I'm going to pass list1 and list2 as an argument. So we have a list, and we— from list we cannot do it, so we will be doing typecasting, and we will be casting our both the list into a set so that we can apply the union function on it. So here I am using the union function, which is the or symbol, and you have to cast both the list, and then I'm going to print the function unified with the two different lists. Here I'm creating list1 with 1, 2, 3, and list2 with 3, 4, 5. So 3 is common, but we want unique items because this is a union function. So 1, 2, 3, 4, 5 is in our output.