2010/10/17 Dirkjan Ochtman <dirk...@ochtman.nl>: > 2010/10/17 Rob Hooft <r...@hooft.net>: >> 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 || r...@hooft.net || http://hooft.net/rob _______________________________________________ Python-nl mailing list Python-nl@python.org http://mail.python.org/mailman/listinfo/python-nl