[Python-ideas] iterable: next() and __iter__() -- and __reset()
spir
denis.spir at gmail.com
Thu Mar 4 12:53:27 CET 2010
On Thu, 4 Mar 2010 12:07:48 +0100
Masklinn <masklinn at masklinn.net> wrote:
Thanks for your reply: I find it helpful; will have a look at the pointed references in a short while.
> In fact, in your case I think supporting slicing/islicing would make far more sense than the solution you've elected)
Actually my Powers type should be "sliceable".
> tripleCubes = [sq for sq in islice(cubes, 6, 16)
> if sq%3 == 0]
Right, but this pattern only replaces cubes(6, 16) by islice(cubes, 6, 16):
tripleCubes = [sq for sq in cubes(6, 16) if sq%3 == 0]
Or do I overlook a relevant point? I guess the proper (and pythonic?) solution would be to implement __getitem__ so as to be able to write:
tripleCubes = [sq for sq in cubes[6:17] if sq%3 == 0]
Does the following match your idea?
def __getitem__(self, ranj):
self.n , self.max = ranj.start-1 , ranj.stop-1
return self
Denis
--
________________________________
la vita e estrany
spir.wikidot.com
More information about the Python-ideas
mailing list