[Python-ideas] Pattern Matching Syntax
Terry Reedy
tjreedy at udel.edu
Thu May 3 17:50:54 EDT 2018
On 5/3/2018 9:16 AM, Joao S. O. Bueno wrote:
> (sorry - my aboe message is about using a dictionary - the "=>" weird
> tokens should j=be just plain ":" -
> the point is that Python açready has syntax to do what is asked)
>
> On 3 May 2018 at 10:15, Joao S. O. Bueno <jsbueno at python.org.br> wrote:
>> What about instead of
>>
>> number = match x:
>> 1 => "one"
>> 2 => "two"
>> 3 => "three"
>> 10 => "ten"
>> _ => "anything"
>>
>> number = {
>> 1 => "one"
>> 2 => "two"
>> 3 => "three"
>> 10 => "ten"
>> }.get(x, "anything")
>>
>> No magic syntax with blocks starting inside an assignment, just to start with.
This was my initial response until I read the further examples that
cannot be done with a dict.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list