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.win...@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor