News for hackers. Stuff that matters.
Re:Five-minute Multimethods in Python by candeira on Wednesday December 07, 2011 @09:53AM (#3323968)
Python doesn't need a switch or case statement because you can write a suite of ad-hoc functions, stick them in a dictionary with your values as keys, and dispatch on the values:

    >>> def first():
    ...     print "a"
    ...
    >>> def second():
    ...     print "beta"
    ...
    >>> caseof = {1: first, 2: second}
    >>> caseof[1]()
    a
    >>> caseof[2]()
    beta
    >>>

There are no comments on this comment yet.