Suggestion for impriving list comprehensions

Steven D. Majewski sdm7g at Virginia.EDU
Fri Jul 27 02:36:48 EDT 2001


On 27 Jul 2001, Paul Svensson wrote:

> 
> No need to cover cases that are clearer expressed
> without involving a list comprehensions at all.
> 
> fib()[:N], I would assume works.
> 

Nope!

Generators don't implement __getitem__ or any of the other
sequece methods ( __len__, ... ) . 

You could, however, define a generator class that implements
__getitem__, et.al.  as well as next. 

-- Steve Majewski






More information about the Python-list mailing list