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 145 views
1 answer 179 views
3 answers 288 views
2 answers 262 views
1 answer 197 views
7 answers 908 views
1 answer 159 views
...