[Tutor] New to this list ....
Russel Winder
russel at winder.org.uk
Fri Mar 30 20:47:01 CEST 2012
Barry,
On Fri, 2012-03-30 at 18:27 +0100, Barry Drake wrote:
> On 30/03/12 17:58, Mark Lawrence wrote:
> > The recipe here
> > http://code.activestate.com/recipes/410692-readable-switch-construction-without-lambdas-or-di/
> >
> > refers to several other recipes which you might want to take a look
> > at, sorry I meant to mention this earlier.
> >
>
> Oh, that's neat. Not worth putting into my little project, but I've
> bookmarked that on for when I need a lot of cases. It also shows how to
> define a class - that was something I had wondered about, but not yet
> tackled.
Be aware of the sensible warnings though. switch in C is generally O(1)
whereas this Python simulacrum remains O(n). The people who comment
saying C switch is always O(n) have clearly never looked at any compiler
output.
Personally, I am in the camp that says: don't use a device that makes it
appear the performance is not what it is. Thus I would prefer
if/elif/else cascade over this device since it is simpler and more
obvious that it is O(n).
But it is a nice example of what Python can achieve even though I would
not use it myself.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder at ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: russel at winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/tutor/attachments/20120330/3da06965/attachment.pgp>
More information about the Tutor
mailing list