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 220 views
1 answer 266 views
3 answers 424 views
2 answers 379 views
1 answer 283 views
7 answers 1,219 views
...