title: Access the sole element of a set
body: <p>I have a <code>set</code> in Python from which I am removing elements one by one based on a condition. When the set is left with just 1 element, I need to return that element. How do I access this element from the set?</p>
  
  <p>A simplified example:</p>
  
  <pre><code>S = set(range(5))
  for i in range(4):
      S = S - {i}
  # now S has only 1 element: 4
  return ? # how should I access this element
  # a lame way is the following
  # for e in S:
  #    return S
  </code></pre>