Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sets

# Python also has sets which you can use
# Keep in mind that sets cannot have duplicate of the same value
# This can be useful for removing doubles in a list

mySet = {1, 2, 2, 3, 4, 5, 10, 10, 15}
print(mySet) # {1, 2, 3, 4, 5, 10, 15}

# You can also create a set with 'set([list elements])'

myList = ['apples', 'bananas', 'oranges', 'grapes']
myList.append('apples')
myList.append('oranges')
print(myList) # ['apples', 'bananas', 'oranges', 'grapes', 'apples', 'oranges']

myNewSet = set(myList)
print(myNewSet) # {'apples', 'bananas', 'oranges', 'grapes'}
Source by www.datacamp.com #
 
PREVIOUS NEXT
Tagged: #python #sets
ADD COMMENT
Topic
Name
2+2 =