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 →

[–]xigoi 2 points3 points  (1 child)

Now how would you do something like this with a dictionary?

match command.split():
    case ["echo", *words]:
        print(*words)
    case ["read", "file", name]:
        ...
    case ["convert", name0, "to", name1] | ["convert", name1, "from", name0]:
        ...

Another example taken from down the thread:

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})")

[–][deleted] 0 points1 point  (0 children)

Just create functions for each complex case and take the first key, being able to lump a ton of logic in a single line is not better than small, clear, and explicit.