I need newbie help

Hornberger, Chris Chris.Hornberger at blackrock.com
Fri May 14 14:24:06 EDT 2004


> Since Python doesn't have a switch statement, you can make your own.
> In Python you could do something like this though:
> 
> selector={
>    x<0    : 'return None',
>    0<=x<1 : 'return 1',
>    1<=x<2 : 'return 2',
>    2<=x<3 : 'return 3',
>    3<=x   : 'return None'
>    }[a]
> 
> if a == 1, it would "return 1".
> 

I'd rather see, as long as there's a known domain of data, using a dictionary to return a known value.

$.02




More information about the Python-list mailing list