Barry, On Fri, 2012-03-30 at 16:42 +0100, Barry Drake wrote: [...] > def getflag(thisflag, results): > if (thisflag == 2): > results[0] += 1 > elif (thisflag == 1): > results[1] += 1 > elif (thisflag == 0): > results[2] += 1 > return(results)
Two thoughts spring to mind:
-- is it possible to arrange the data model such that the value of the
thisflag is the index into the sequence, then:
def getflag(thisflag, results):
results[thisflag] += 1
return results
-- seriously "overengineered" for this particular example but the
replacement for switch statement is a dictionary and function pointers.
from functools import partial
def alt(thisflag, results):
def setflag(x):
results[x] += 1
{
0: partial(setflag, 2),
1: partial(setflag, 1),
2: partial(setflag, 0),
}[thisflag]()
return results
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:[email protected]
41 Buckmaster Road m: +44 7770 465 077 xmpp: [email protected]
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
