Python Pseudo-Switch

Terry Reedy tjreedy at udel.edu
Sat May 7 21:27:38 EDT 2005


"James Stroud" <jstroud at mbi.ucla.edu> wrote in message 
news:200505071736.39806.jstroud at mbi.ucla.edu...
> Because of my poorly designing a database, I have recently found it 
> necessary
> to explore the wonders of the Python pseudo-switch:
>
> do_case = { "A" : lambda x: x["bob"],
>            "B" : lambda x: x["carol"],
>            "C" : lambda x: "Ted",
>            "D" : lambda x: do_something(x) }
>
> my_thing = do_case[get_value_from_thin_air()](adict)
>
> How to handle this kind of thing when lambda is removed from the 
> language,
> beside the obvious def'ing those tiny little functions?

I don't believe any cast-in-concrete decision about lambda has been made 
yet.  I expect there will be a PEP for removals when appropriate.  Comments 
such as this will bolster the case against removal without replacement if 
then resubmitted

TJR







More information about the Python-list mailing list