I have this code that intersperses from python: most elegant way to intersperse a list with an element.
def joinit(iterable, delimiter):
it = iter(iterable)
yield next(it)
for x in it:
yield delimiter
yield x
I would like to do about the same thing, only that I can add an element n
times between the elements in the list.
Example:
joinNTimes(3,"a",[1,2,3])
Will become
[1,"a","a","a",2,"a""a","a",3,"a","a","a"]
Thanks.