On Oct 19, 2:51 am, Hendrik van Rooyen <hend...@microcorp.co.za> wrote: > On Sunday, 18 October 2009 11:31:19 Paul Rubin wrote: > > > Hendrik van Rooyen <hend...@microcorp.co.za> writes: > > > Standard Python idiom: > > > > if key in d: > > > d[key] += value > > > else: > > > d[key] = value > > > The issue is that uses two lookups. If that's ok, the more usual idiom is: > > > d[key] = value + d.get(key, 0) > > I was actually just needling Aahz a bit. The point I was trying to make > subliminally, was that there is a relative cost of double lookup for all > cases versus exceptions for some cases. - Depending on the frequency > of "some", I would expect a breakeven point. > > - Hendrik
Looks similar to this idiomrelated dummyflag and formhandling edit I try understand some time whether it matters, default=False, same output, later chosen of nothing else to avoid casting since all inputs are text and no input is boolean: view=db.BooleanProperty(default=False,verbose_name="view") #view = not boo(self.request.get('invisible')) view = self.request.get('invisible',None) is not None Easier to keep things positive the longest we can so that above rather handles variable 'visible' than 'invisible' since double negatives, triple negatives or more unintelligibilize. Hence a 3rd way, all positive, shall easify readability, perhaps switch default from false to true. -- http://mail.python.org/mailman/listinfo/python-list