a break for comprehensions
Steven D. Majewski
sdm7g at Virginia.EDU
Thu Jul 26 14:46:03 EDT 2001
>>> [ x for x in iter( iter([1,2,3,4,5,6,7,8,9]).next, 6 ) ]
[1, 2, 3, 4, 5]
>>> print iter.__doc__
iter(collection) -> iterator
iter(callable, sentinel) -> iterator
Get an iterator from an object. In the first form, the argument must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the sentinel.
>>>
iter(list).next gives you a callable object that sequentially
returns each value -- which gets fed to the 2 arg variant
of iter that takes a callable and a sentinel. When it hits
the sentinal value, it stops.
-- Steve Majewski
More information about the Python-list
mailing list