Mega Code Archive

 
Categories / Python / Data Structure
 

Sets

basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] fruit = set(basket)                     # create a set without duplicates print fruit print 'orange' in fruit                 # fast membership testing print 'crabgrass' in fruit