Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #85225

Re: basic generator question

References <mat6gt$e4j$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-02-04 10:15 -0700
Subject Re: basic generator question
Newsgroups comp.lang.python
Message-ID <mailman.18471.1423070186.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Feb 4, 2015 at 6:23 AM, Neal Becker <ndbecker2@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']

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: basic generator question Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-04 10:15 -0700

csiph-web