 <p>You need to make this operation optional if <code>value</code> is empty:</p> <pre><code> if value: data.append((next(value), value)) </code></pre> <p>This change works for me:</p> <pre><code>if value: try: data.append(next(value), value) except StopIteration: pass </code></pre>