set_pop.py 442 B

123456789101112131415161718
  1. s = {1}
  2. print(s.pop())
  3. try:
  4. print(s.pop(), "!!!")
  5. except KeyError:
  6. pass
  7. else:
  8. print("Failed to raise KeyError")
  9. # this tests an optimisation in mp_set_remove_first
  10. # N must not be equal to one of the values in hash_allocation_sizes
  11. N = 11
  12. s = set(range(N))
  13. while s:
  14. print(s.pop()) # last pop() should trigger the optimisation
  15. for i in range(N):
  16. s.add(i) # check that we can add the numbers back to the set
  17. print(list(s))