basic generator question

Ian Kelly ian.g.kelly at gmail.com
Wed Feb 4 12:15:35 EST 2015


On Wed, Feb 4, 2015 at 6:23 AM, Neal Becker <ndbecker2 at gmail.com> wrote:
> class rpt:
>   def __init__ (self, value, rpt):
>     self.value = value; self.rpt = rpt
>   def __call__ (self):
>     for i in range (self.rpt):
>       yield self.value

Note that this class is just reimplementing itertools.repeat.

>>> list(itertools.repeat('hello', 5))
['hello', 'hello', 'hello', 'hello', 'hello']



More information about the Python-list mailing list