2010/10/17 Dirkjan Ochtman <[email protected]>:
> 2010/10/17 Rob Hooft <[email protected]>:
>> En zo?
>>
>> class Window(object):
>>        def __init__(self, n):
>>                self.n = n
>>
>>        def __call__(self, list):
>>                ret = []
>>                for i in list:
>>                        if len(ret) == self.n:
>>                                yield ret
>>                                ret = ret[1:]
>>                        ret.append(i)
>>                if len(ret) == self.n:
>>                        yield ret
>>
>> lijst = [1, 2, 3, 3, 4, 10 , 3 ,2, 2, 1]
>>
>> w=Window(3)
>> for three in w(lijst):
>>        print three
>
> Waarom gebruik je hier een class? Je kan die hele __call__() gewoon
> als functie schrijven.

Dat vind ik niet pythonic. De grootte van het window instellen is een
andere functie dan het itereren, en dat wil ik dus scheiden. Zie je
een probleem met het gebruiken van een class?

Rob

-- 
Rob W. W. Hooft || [email protected] || http://hooft.net/rob
_______________________________________________
Python-nl mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-nl

Antwoord per e-mail aan