On Feb 5, 2010, at 2:42 PM, Paul McNett wrote:
> 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.
They are more memory-efficient, because you don't have to create a
complete copy of the list, as you would in a list comp. But since the maximum
length of the list would be one, it's not an issue. You could use a genexp if
you wanted:
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)
try:
pks.next()
return True
except StopIteration:
return False
-- Ed Leafe
_______________________________________________
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]