Most Pythonic way equivalent for: while ((x = next()) != END)
<p>What's the best Python idiom for this C construct?</p>

<pre><code>while ((x = next()) != END) {
    ....
}
</code></pre>

<p>I don't have the ability to recode next().</p>

<p>update:  and the answer from seems to be:</p>

<pre><code>for x in iter(next, END):
    ....
</code></pre>

<p>@Mark Harrison's answer:</p>

<pre><code>for x in iter(next_, END):
    ....
</code></pre>

<p>Here's an excerpt from <a href="http://docs.python.org/library/functions.html">Python's documentation</a>:</p>

<pre><code>iter(o[, sentinel])
</code></pre>

<blockquote>
  <p>Return an iterator object.
  <em>...(snip)...</em> If the second argument, <code>sentinel</code>, is given, then <code>o</code> must be
  a callable object. The iterator
  created in this case will call <code>o</code>
  with no arguments for each call to its
  <code>next()</code> method; if the value returned
  is equal to <code>sentinel</code>,
  <code>StopIteration</code> will be raised,
  otherwise the value will be returned.</p>
</blockquote>
