[Python-ideas] Inline assignments using "given" clauses

Kirill Balunov kirillbalunov at gmail.com
Fri May 11 11:00:25 EDT 2018

2018-05-11 17:06 GMT+03:00 Clint Hepner <clint.hepner at gmail.com>:

> (This reminds that I wish ``iter`` could take a predicate instead of a
> sentinel as its second argument. Then
> you could just write
>     for cmd in iter(get_command, lambda x: x.token == CMD_QUIT):
>         cmd.do_something()
> )
But you can do it right now:

class P:
    def __init__(self, key):
        self.key = key
    def __eq__(self, other):
        return self.key(other)

for cmd in iter(get_command, P(lambda x: x.token == CMD_QUIT)):

With kind regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180511/66cf4435/attachment.html>

More information about the Python-ideas mailing list