python (65.1k questions)
javascript (44.2k questions)
reactjs (22.7k questions)
java (20.8k questions)
c# (17.4k questions)
html (16.3k questions)
r (13.7k questions)
android (12.9k questions)
Invert a test with structural pattern matching
I've been converting if-elif-chains to structural pattern matching but am having difficulty with inverted tests.
It is easy to make cases that match any of the supported patterns (literal, class, mapp...
Raymond Hettinger
Votes: 0
Answers: 1
Conditional cases in match statement python3.10 (structural pattern matching)
I'm currently developing something and was wondering if the new match statement in python 3.10 would be suited for such a use case, where I have conditional statements.
As input I have a timestamp and...
Jeroen Vermunt
Votes: 0
Answers: 2
Class pattern is matching the wrong cases
I'm writing an object serializer but am having issues where the class patterns are not matching the expected cases:
def dump_obj(x):
match(x):
case list():
emit('L')
...
Raymond Hettinger
Votes: 0
Answers: 1
Pattern matching to check a protocol. Getting TypeError: called match pattern must be a type
I need to match cases where the input is iterable. Here's what I tried:
from typing import Iterable
def detector(x: Iterable | int | float | None) -> bool:
match x:
case Iterable():
...
Raymond Hettinger
Votes: 0
Answers: 1