title: Class that iterate over a set
body: <pre><code>class Ordered:
      def __init__(self,aset):
          self.aset = aset
      def __iter__(self):
          for v in sorted(self.aset): # iterate over list of values returned by sorted
              yield v
  </code></pre>
  
  <p>the function takes a set and return a list</p>
  
  <p>the set is always </p>
  
  <p>s = {1, 2, 4, 8, 16}</p>
  
  <p>for example:</p>
  
  <pre><code>s = {1, 2, 4, 8, 16}
  i = iter(Ordered(s))
  print(next(i))
  print(next(i))
  s.remove(8)
  print(next(i))
  s.add(32)
  print(next(i))
  print(next(i))
  
  it should prints 1 2 4 16 32
  </code></pre>
  
  <p>But when my function takes</p>
  
  <pre><code>[next(i), next(i), s.remove(8), next(i), next(i), s.add(32), next(i)]
  </code></pre>
  
  <p>it should print</p>
  
  <pre><code>[1, 2, None, 4, 16, None, 32]
  </code></pre>
  
  <p>But instead, it prints:</p>
  
  <pre><code>[1, 2, None, 4, 8, None, 16]
  </code></pre>
  
  <p>can someone tell me how to fix it? thanks</p>
  
  <p>I posted the error I got below to help to understand:</p>
  
  <pre><code>39 *Error: Failed [next(i), next(i), s.remove(8), next(i), next(i), s.add(32), next(i)] == [1, 2, None, 4, 16, None, 32]
        evaluated: [1, 2, None, 4, 8, None, 16] == [1, 2, None, 4, 16, None, 32]
  42 *Error: [next(i), next(i), next(i), s.add(3), next(i), s.add(10), s.add(32), next(i), next(i), next(i)] raised exception; unevaluated: [1, 2, 4, None, 8, None, None, 10, 16, 32]
  46 *Error: Failed [next(i), s.remove(2), s.remove(4), s.remove(8), next(i)] == [1, None, None, None, 16]
        evaluated: [1, None, None, None, 2] == [1, None, None, None, 16]
  49 *Error: Failed [next(i), s.remove(2), next(i), s.remove(4), s.remove(8), next(i)] == [1, None, 4, None, None, 16]
        evaluated: [1, None, 2, None, None, 4] == [1, None, 4, None, None, 16]
  </code></pre>