Extracting an Element from a Set in Python
To extract a random element from a set, we need to apply the pop method. We don't pass anything to its parameter.
Let us have a set:
pythonst = {'a', 'b', 'c'}
Let's extract a random element from it:
pythonprint(st.pop()) # 'b'
The element after extraction is removed from the set. Let's look at the original set:
pythonprint(st) # {'b', 'c'}
Задание 1
Given a set:
pythonst = {1, 2, 3, 4, 5}
Reduce its length by one.
Задание 2
Given a set:
pythonst = {'a1', 'b2', 'c3', 'd4'}
Perform a sequential extraction of two elements from it.