# sample_list is defined list
sample_list =[1,2,3,'seeker',3,7.5]# set() to convert list to set
sample_set =set(sample_list)print(sample_set)#printing set# Output:# {1, 2, 3, 7.5, ‘seeker’}# Time of execution 0.00016019
# For Loop to convert list to set Python# In this method, we use for loop to access each element of a list and# add that element in a set by using add() function.# sample_list is defined list
sample_list =[1,2,3,'seeker',3,7.5]# set() to convert list to set
sample_set =set()# defining set#using for loopfor i in sample_list:#adding i to b
sample_set.add(i)print(sample_set)# Output:# {1, 2, 3, 7.5, ‘seeker’}# Time of Execution 0.00019580
# Using Set Comprehension to convert list to set Python# In this method, we will be using set comprehension.# a is defined list
a =[1,2,3,'seeker',3,7.5]
t ={x for x in a}# set comprehensionprint(t)# Output:# {1, 2, 3, 7.5, ‘seeker’}# Time of execution 0.00018290
# Using dict.fromkey() convert list to set Python# using the dictionary fromkeys() method.# The only disadvantage of this method is we don’t get set in an orderly manner.# a is defined list
a =[1,2,3,'seeker',3,7.5]# Using dict.fromkeys() method
x =list(dict.fromkeys(a))
converted_set =set(x)print(converted_set)# Output:# {1, 2, 3, 7.5, ‘seeker’}
convert set to list python time complexity method 1
# sample_list is defined list
sample_list =[1,2,3,'seeker',3,7.5]# set() to convert list to set
sample_set =set(sample_list)print(sample_set)#printing set
convert set to list python time complexity method 2
# sample_list is defined list
sample_list =[1,2,3,'seeker',3,7.5]# set() to convert list to set
sample_set =set()# defining set#using for loopfor i in sample_list:#adding i to b
sample_set.add(i)print(sample_set)