I'm trying to generate a series of (empty) lists using a for loop in python, and I want the name of the list to include a variable. e.g. y0, y1, y2 etc. Ideally looking something like this:
for a in range (0,16777216):
global y(a)=[]
why wouldn't you do a dictionary of lists?
y = {}
for a in range (0,16777216):
y[a] = []
also for brevity: https://stackoverflow.com/a/1747827/884453
y = {a : [] for a in range(0,16777216)}
Not sure if this is quite what you want but couldn't you emulate the same behavior by simply creating a list of lists? So your_list[0] would correspond to y0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With