Project Level 1: Beginner
This project is designed for beginner learners who are still learning and practicing Python fundamentals.
Project Description
Let’s have another project on lists since they are a key data type in Python whenever we need to store multiple items.
Your task for today is to write a program that merges two lists into one and removes any common items between them.
Start by pasting these two lists in an empty Python script:
list1 = [1, 2, 3, 4]
list2 = [3, 4, 5, 6]
Then, add some code so your program should:
Merge these two lists into one single list.
Remove the common/duplicate items
Print out the updated list.
Expected Output
Here is what the program should print out after you run it:
Learning Benefits
List Merging: Practice combining multiple lists into one.
List Comprehension: Use list comprehension to filter elements efficiently.
Removing Duplicates: Understand how to remove elements that appear in both lists while keeping the unique ones.
Prerequisites
Required Libraries: No libraries are needed for this project.
Required Files: No files are needed for this project.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
See our solution below after you have tried to code yours.
alternate solution using set operator -
list1 = [1, 2, 3, 4]
list2 = [3, 4, 5, 6]
list3=list1+list2
my_set = set(list3)
my_list=list(my_set)
print(my_list)