On 2/5/10 11:19 AM, Ed Leafe wrote: > On Feb 5, 2010, at 2:08 PM, Paul McNett wrote: > >> + def hasPK(self, pk): >> + """Return True if the passed pk is present in the dataset.""" >> + pks = (v[self.KeyField] for v in self._records) >> + for trial_pk in pks: >> + if trial_pk == pk: >> + return True >> + return False > > This should be faster: > > def hasPK(self, pk): > """Return True if the passed pk is present in the dataset.""" > kf = self.self.KeyField > pks = [v[kf] for v in self._records > if v[kf] == pk] > return bool(pks)
I can see the local kf assignment being faster, but I was under the impression that generator expressions were faster than list comprehensions. Granted, I haven't really been keep current with optimization topics. Paul _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev Searchable Archives: http://leafe.com/archives/search/dabo-dev This message: http://leafe.com/archives/byMID/[email protected]
