create set from list python code example
Example 1: empty set python
# Distinguish set and dictionary while creating empty set
# initialize a with {}
a = {}
# check data type of a
print(type(a))
# initialize a with set()
a = set()
# check data type of a
print(type(a))
Example 2: convert list to set python
names = ['Barry', 'Alice', 'Bob', 'Bob']
unique_names = set(names)
# Result:
# {'Alice', 'Barry', 'Bob'}
Example 3: list set python
myset = {"apple", "banana", "cherry"}
mylist = ["dog", "cat", "humanoid"]
mydict = {'planet': 'blue', 'edges': 4, 'perimeter':15}