Do you have real-world use cases for map's None fill-in feature?

Szabolcs Nagy nszabolcs at gmail.com
Tue Jan 10 11:35:50 EST 2006


> There are so many varieties of iterator that it's probably not workable
> to alter the iterator API for all of the them.

i always wondered if it can be implemented:

there are iterators which has length:
>>> i = iter([1,2,3])
>>> len(i)
3

now isn't there a way to make this length inheritible?
eg. generators could have length in this case:
>>> g = (x for x in [1,2,3])
>>> # len(g) == len([1,2,3]) == 3

of course in special cases length would remain undefined:
>>> f = (x for x in [1,2,3] if x>2)
>>> # len(f) == ?

IMHO there are special cases when this is useful:
L=list(it)
here if it has length, then list creation can be more effective
(required memory is known in advance) 

nsz




More information about the Python-list mailing list