count items in generator

BartlebyScrivener rpdooling at gmail.com
Sun May 14 14:40:15 EDT 2006


>> True.  Changing the except clause here to

>> except: return sum(1 for x in iterable)

>> keeps George's optimization (O(1), not O(N), for containers) and is a
>> bit faster (while still O(N)) for non-container iterables.

Every thing was going just great. Now I have to think again.

Thank you all.

rick




More information about the Python-list mailing list