case/switch statement?

Terry Hancock hancock at anansispaceworks.com
Mon Jun 13 13:04:40 EDT 2005


On Sunday 12 June 2005 07:33 am, Dan Sommers wrote:
> > There is no case statement in Python. If you don't care about
> > readability, one alternative is to use a dictionary:
> 
> > case = {5: do_this, 6: do_that}
> > case.get(x, do_something_else)()
> 
> I find this very readable.  YMMV.

Yeah, and I find this even more so:
case =  {
        5: do_this,
        6: do_that,
        }
case.get(x, do_default)()

Which is looking pretty close to a case statement, anyway.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list