[Python-ideas] 'where' statement in Python?

Nick Coghlan ncoghlan at gmail.com
Tue Jul 20 23:07:57 CEST 2010


On Wed, Jul 21, 2010 at 12:57 AM, Andrey Popp <8mayday at gmail.com> wrote:
> Hello,
>
> PEP-3150 is awesome, just a small addition — why not to allow
> one-liners `where`s:
>
>    a = (b, b) where b = 43
>
> And that also make sense for generator/list/set/dict comprehensions:
>
>    mylist = [y for y in another_list if y < 5 where y = f(x)]

As with any other suite, a one-liner would be allowed on the same line
as the colon:

  a = (b, b) where: b = call_once_only()
  mylist = [y for y in another_list if y < x] where: x = call_once_only()

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list