Given an iterator i
, I want an iterator that yields each element n
times, i.e., the equivalent of this function
def duplicate(i, n):
for x in i:
for k in range(n):
yield x
Is there an one-liner for this?
Related question: duplicate each member in a list - python, but the zip
solution doesn't work here.