[Python-ideas] Yet Another Switch-Case Syntax Proposal

Philipp A. flying-sheep at web.de
Sat Apr 26 15:03:32 CEST 2014


what y’all are missing about switch/case is that it’s *not* necessarily a
series of comparisons in most languages.

in essence, it’s a hashmap lookup with (in some languages) optional
comparisons.

in python, the most similar thing is something like this:

def branch_2_3():
    spam(1)
    spam(6)

{
    'key1': lambda: eggs += lay_eggs(), #branch 1
    'key2': branch_2_3,
    'key3': branch_2_3,
}[value]()

which is of course completely ugly and unnecessarily complicated for cases
where multiple keys lead to the same branch.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140426/178fc457/attachment.html>


More information about the Python-ideas mailing list