It is necessary to create a cycle for generating a list in which each subsequent value is formed from the previous one. Below is an example of the algorithm.

var = 'a' list = [var, list[0] + 'b', list[1] + 'c', list [2] + 'd'] 

Exit from the loop after forming 4 values

    2 answers 2

     l = ['a'] for _ in range(3): l.append(l[-1] + chr(ord(l[-1][-1]) + 1)) print(l) # → ['a', 'ab', 'abc', 'abcd'] 
       >>> import itertools >>> list(itertools.accumulate('abcd')) ['a', 'ab', 'abc', 'abcd']