On Tue, 06 Apr 2010 16:54:18 +0000, Duncan Booth wrote: > Albert van der Horst <alb...@spenarnc.xs4all.nl> wrote: > >> Old hands would have ... >> stamp =( weight>=1000 and 120 or >> weight>=500 and 100 or >> weight>=250 and 80 or >> weight>=100 and 60 or >> 44 ) >> >> (Kind of a brain twister, I think, inferior to C, once the c-construct >> is accepted as idiomatic.) > > I doubt many old hands would try to join multiple and/or operators that > way. Most old hands would (IMHO) write the if statements out in full, > though some might remember that Python comes 'batteries included': > > from bisect import bisect > WEIGHTS = [100, 250, 500, 1000] > STAMPS = [44, 60, 80, 100, 120] > > ... > stamp = STAMPS[bisect(WEIGHTS,weight)]
Isn't that an awfully heavyweight and obfuscated solution for choosing between five options? Fifty-five options, absolutely, but five? -- Steven -- http://mail.python.org/mailman/listinfo/python-list