Switch statement

Joseph L. Casale jcasale at activenetwerx.com
Sun Mar 10 18:51:58 CET 2013

> switch = { 

>     'A': functools.partial(spam, a),
>     'B': lambda b, c=c: ham(b, c),
>     'C': eggs,
>     }
> switch[letter](b)

That's cool, never even thought to use lambdas.

> functools.partial isn't always applicable, but when it is, you should
> prefer it over lambda since it will be very slightly more efficient.

Ok, haven't used this before but I will give it a read!

Much appreciated Steven!

More information about the Python-list mailing list