How to remove a random item from a set in Python

1 Answer

0 votes
st = {'python', 'java', 'c', 'c++', 'c#'}

removed = st.pop()
print(st)
print(removed)

removed = st.pop()
print(st)
print(removed)



'''
run:

{'python', 'c#', 'c', 'c++'}
java
{'c#', 'c', 'c++'}
python

'''


 



answered Aug 8, 2022 by avibootz

Related questions

1 answer 139 views
1 answer 173 views
3 answers 265 views
2 answers 259 views
1 answer 195 views
7 answers 876 views
1 answer 149 views
...