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 221 views
1 answer 268 views
3 answers 427 views
2 answers 381 views
1 answer 285 views
7 answers 1,222 views
...