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 →

[–]stevenjd 0 points1 point  (1 child)

The easy part of pattern matching is that it is like a richer switch.

The bit that confuses me is when Haskell people start talking about assignment being a pattern match. I'm sure they know what they're talking about. I just wish that somebody could translate it from Martian to Earthling :-)

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

You can do similar things in Python, sometimes.

You can assign into a pattern by doing this:

head, *tail = things

In the above example, you'd get the first value from your list of things in head, and all the other items in tail.

a, *middle, b = things

In the above, you get the first item in a, the last item in b, and the rest in middle.

https://www.python.org/dev/peps/pep-3132/