(Oct-16-2019, 03:52 PM)jefsummers Wrote: What you likely want is a list of lists. Nested for loops will do this nicely.
num_rows = int(input("Rows: ")) num_cols = int(input("Cols: ")) for row in range(num_rows): for col in range(num_cols): #Here is where you get the data for each row and col #new_data is the row you are creating from the input data new_data.append(whatever you get as a cell of input) #Once you assemble a row's worth of data, then table = table.append(new_data) print(table) #To access a single cell, access by row and column single_cell = table[row][col]Designed this as a format - it obviously does not work as written, but is meant to spur you in a direction
I've been learning this approach with regard to iterating over rows/columns to fill arrays in VBA. Python doesn't support arrays, though, so I think the main source of confusion for me is still where I would be storing that new data. What is new_data? If it's a list then the program needs to be able to create n lists when the user says there will be n rows (for example).
(Oct-16-2019, 03:33 PM)buran Wrote:(Oct-16-2019, 03:29 PM)Mark17 Wrote: Can I use iteration (i.e. a for loop) to create variable names themselves? What I actually want are names of the lists that will correspond to the rows.
Although possible, creating variable names dynamically is really bad idea
use proper data structure like dict or list
https://python-forum.io/Thread-dynamical...7#pid91757
I went through Ned Batchelder's blog post on this (mentioned in the link you provided). I don't really understand it. I hear what he's saying (kind of) about going up a level in the data modeling. I don't understand why. Seeing a simple example and the kind of traceback that can result might help me understand a bit more.