Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How To Remove Elements From a Set using pop() function in python

"""
We can use the pop() function to remove the last item in a set,
but because a set is unordered, we will not know what item will be removed.
The pop() function will return the element that was removed
"""

mySet = {1, 2, 3}
removedElement = mySet.pop()
print(removedElement)
print(mySet)

"""
Output:
1
{2, 3}
"""
Source by liu-111.medium.com #
 
PREVIOUS NEXT
Tagged: #How #To #Remove #Elements #From #Set #function #python
ADD COMMENT
Topic
Name
1+7 =