Assignment and comparison in one statement
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Sat May 24 07:38:58 EDT 2008
On Sat, 24 May 2008 13:13:08 +0200, Johannes Bauer wrote:
> George Sakkis schrieb:
>
>>> However, this "assignment and comparison" is not working. What's the
>>> "Python way" of doing this kind of thing?
>>
>> The most obvious and readable of course: use two statements, as one
>> should do regardless of the language, instead of resorting to error-
>> prone hacks.
>
> As I said in the reply to Carl, this might be okay for if-clauses, but
> is bothering me with while-loops.
Then try to write the ``while`` loop as ``for`` loop and move the
comparison into a generator function, or use the two argument variant of
`iter()`, or `itertools.takewhile()`.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list