On Sun, 8 May 2022 at 19:38, Ethan Furman <[email protected]> wrote:
>
> On 5/8/22 05:08, Valentin Berlier wrote:
>
>
> > This would make it really useful in if statements and list comprehensions.
> Here are a couple motivating examples:
> >
> > # Buy every pizza on the menu
> > cost_for_all_pizzas = sum(
> > price for food in menu
> > if ({"type": "pizza", "price": price} := food)
> > )
>
> What exactly is that last line testing, and how does it differentiate between
> "pizza" and, say, "salad"?
And what is wrong with
cost_for_all_pizzas = 0
for food in menu:
match food:
case {"type": "pizza", "price": price}:
cost_for_all_pizzas += price
Seriously, people are just getting used to match statements (I had to
look the syntax up for the above) so IMO it's a bit early to be trying
to cram them into dubious one-liners.
Paul.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/XRBWE4AMN754NNYZNTT3XEJUQ4N7P46D/
Code of Conduct: http://python.org/psf/codeofconduct/