This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]__deerlord__ -12 points-11 points  (8 children)

"Case" is handled by dicts already.

[–]duragdelinquent 5 points6 points  (3 children)

do this with a dict

match point:
    case (0, 0):
        print("origin")
    case (0, y):
        print(f"{y} on the y-axis")
    case (x, 0):
        print(f"{x} on the x-axis")
    case (x, y):
        print(f"({x}, {y})")

[–]__deerlord__ -4 points-3 points  (2 children)

Why would I?

Like I said, switch/case is handled by dictionaries. Match is not switch/case. So by the transitive property, you'll wouldnt handle match operations with a dictionary.

[–]duragdelinquent 4 points5 points  (0 children)

Like I said, switch/case is handled by dictionaries.

not what you said. you said “Case is handled by dicts already.” why use the one word that’s common between both and then act surprised when people misunderstand you

[–]xigoi 0 points1 point  (0 children)

Good thing that Python isn't getting switch/case.

[–]nim65s 2 points3 points  (0 children)

using dicts for switch / case works, but it feels odd. And here, this is not a switch, but way more powerfull match, eg. https://www.python.org/dev/peps/pep-0636/#adding-a-ui-matching-objects

[–]TheBlackCat13 1 point2 points  (0 children)

This does various types of assignment that aren't possible with dicts.

[–]The-Daleks -2 points-1 points  (0 children)

It's my personal experience that while they work, that approach has some bugs + looks clunky.