Well, is that necessary? It is better to do as below.
D = {'list{}'.format(n):list() for n in range(1, 11)}
print(D)
{'list1': [], 'list2': [], 'list3': [], 'list4': [], 'list5': [], 'list6': [], 'list7': [], 'list8': [], 'list9': [], 'list10': []}
Of course, you can do as the questioner asks, but you need to use reflection. First, don't confuse the code written by the questioner with the code your computer understands.
Please refer to the sample below.
import sys
mod = sys.modules[__name__]
for n in range(1, 11):
setattr(mod, 'list{}'.format(n), [])
print(list1)
print(list10)
[]
[]
© 2025 OneMinuteCode. All rights reserved.