I am pretty new to python and looking for how to create a list of empty lists having names more efficiently than presented below
I would like to have some names to the lists.
JavaScript
x
17
17
1
flattenlist_x1 = []
2
flattenlist_x2 = []
3
flattenlist_x3 = []
4
flattenlist_x4 = []
5
flattenlist_x5 = []
6
flattenlist_x6 = []
7
flattenlist_x7 = []
8
flattenlist_x8 = []
9
flattenlist_x9 = []
10
flattenlist_x10 = []
11
flattenlist_x11 = []
12
flattenlist_x12 = []
13
14
flattenlist_list = [flattenlist_x1, flattenlist_x2, flattenlist_x3, flattenlist_x4,
15
flattenlist_x5, flattenlist_x6, flattenlist_x7, flattenlist_x8,
16
flattenlist_x9, flattenlist_x10, flattenlist_x11, flattenlist_x12]
17
Advertisement
Answer
Beacuse you want it to have name, how about using dict?
JavaScript
1
5
1
flattenlist_list = {}
2
for i in range(1,13):
3
flattenlist_list['flattenlist_x'+str(i)]=[]
4
print(flattenlist_list)
5