list comprehension question

James_Althoff at i2.com James_Althoff at i2.com
Wed Mar 27 19:29:45 EST 2002


[Tim Peters]
> No.  len([f(x) for x in y]) == len(y) whenever no exception occurs,
> regardless of the form of f() or type of y.

>>>
>>> class Y:
...   def __iter__(self):
...     return iter(xrange(5))
...   def __len__(self):
...     return 10
...
>>> def f(x): return x
...
>>> y = Y()
>>>
>>> len([f(x) for x in y]) == len(y)
0
>>>
Jim





More information about the Python-list mailing list