Insert item before each element of a list

Ian Kelly ian.g.kelly at gmail.com
Mon Oct 8 16:04:38 EDT 2012


On Mon, Oct 8, 2012 at 1:52 PM, Joshua Landau
<joshua.landau.ws at gmail.com> wrote:
> But it's not far. I wouldn't use Ian Kelly's method (no offence), because of
> len(x): it's less compatible with iterables. Others have ninja'd me with
> good comments, too.

That's fair, I probably wouldn't use it either.  It points to a
possible need for a roundrobin variant that truncates like zip when
one of the iterables runs out.  It would have to do some look-ahead,
but it would remove the need for the len(x) restriction on
itertools.repeat.



More information about the Python-list mailing list