def test(): x = ['test'] * 20 exec("lst = [x[i] for i in range(10)]") print(lst) test()