I want to design a generator as gen(num):
the idea is to generator a sequence of number. such as if num=3
, the sequence will be (1,2,3,2,1,2,3,2,1.....)
. if num=4
, the sequence will be (1,2,3,4,3,2,1,2,3,4,3,2,1,....)
def gen(num)
And how to use this generator in a for loop?
such as
a = [1,2,3,4,5]
b = gen(10)
for item in a:
a+next(b)
it is good to use next(b)
or we have better solution?