In this Python set program, we will convert list to a set with the help of the below-given steps.
What is set?
Sets are used to store multiple items in a single variable.
The set is one of 4 built-in data types in Python used to store collections of data.
It is an unordered collection data type that is iterable, mutable and has no duplicate elements.
Convert list to a set:
Steps to solve the program
1. Create a list using [].
2. Add some elements in the list.
3. Convert a list to a set using set() function.
4. Print the output.
List = [1,2,3,4,5]
list_set = set(List)
print("Original list: ",List)
print("List to set: ",list_set)
Output :
Original list: [1, 2, 3, 4, 5]
List to set: {1, 2, 3, 4, 5}
Related Articles
Python program to convert a set to a list.
Python program to find the maximum element in a set.
Python program to find the minimum element in a set.
Python program to find the sum of elements in a set.
Python program to find the average of elements in a set.
Python program to check if all elements in a set are even.