Python Lists Under While Loop -


i want make while loop kind of this

list=[]     while x in range(r):         list-x="something" 

where each time loop begins makes new list number (x). if loops on 5 times there different lists: list(1) list(2) list(3) list(4). '

is possible?

you able vars() function:

for in range(5):     list_name = ''.join(['list', str(i)])     vars()[list_name] = [] 

you can reference each list:

print(list1) --> [] print(list2) --> []  etc... 

you can achieve using locals() or globals() functions below:

for in range(5):     locals()['list{}'.format(i)] = [] 

hope helps!


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -