Articles → Python → Sets in python

Sets in python






Purpose





Example


mySet = {1,2,3,4,5,2}

print(mySet)





Click to Enlarge


Add duplicate elements in sets




mySet = {1,2,3,4,5}

mySet.add(1)

print(mySet)





Click to Enlarge


Converting list to set




mySet = {1,2,3,4,5}

myList = [1,2,1]

print(set(myList))





Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, March 07, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250