Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41023
| From | "Joseph L. Casale" <jcasale@activenetwerx.com> |
|---|---|
| Subject | RE: Switch statement |
| Date | 2013-03-10 17:51 +0000 |
| References | <513ca430$0$6512$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3157.1362937989.2939.python-list@python.org> (permalink) |
> 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!
jlc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Switch statement "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-03-10 14:16 +0000
Re: Switch statement Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-10 15:18 +0000
RE: Switch statement "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-03-10 17:51 +0000
Re: Switch statement Terry Reedy <tjreedy@udel.edu> - 2013-03-10 18:02 -0400
csiph-web