Making the case for repeat

pataphor pataphor at
Fri Jun 5 07:04:37 EDT 2009

Gabriel Genellina wrote:

> Ok, you're proposing a "bidimensional" repeat. I prefer to keep things
> simple, and I'd implement it in two steps. 

But what is simple? I am currently working on a universal feature
creeper that could replace itertools.cycle, itertools.repeat,
itertools.chain and reverse and also helps to severely cut down on
itertools.islice usage. All within virtually the same parameter
footprint as the last function I posted. The problem is posting *this*
function would kill my earlier repeat for sure. And it already had a
problem with parameters < 0 (Hint: that last bug has now become a
feature in the unpostable repeat implementation)

> Note that this doesn't require any additional storage. Second step would
> be to build a bidimensional repeat:

Thanks for reminding me, but the storage savings only work for a
'single cycle' function call. But I guess one could special case for

> py> one = chain.from_iterable(repeat(elem, 3) for elem in thing)
> py> two = chain.from_iterable(tee(one, 2))
> py> list(two)
> ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4', '1', '1',
> '1', '2',
>    '2', '2', '3', '3', '3', '4', '4', '4']
> Short and simple, but this one requires space for one complete run (3*4
> items in the example).

Really? I count 4 nested functions and an iterator comprehension. I
guess it's a tradeoff between feature creep and function nesting


More information about the Python-list mailing list