I want to remove last item in during the loops

Are you looking for something like this?

from itertools import product
p = list(product([1,2,3], repeat = 2))
a = [str(p[:-i]) for i in range(1, len(p))]

Setareh.gh (3.8 KB)

2 Likes