Hello everyone,

I have to code an array that in each row, it has 16 columns! So I called it myself a 17 dimensional array but I was wondering what data sturcture in Python can best represent this keeping in mind that, it should be easily addressable and modifible.

For example, what I had in mind initially was a a list of lists, where the inner list has 16 entries:

0  1               15
0 [ [] [] [] [] ...... [] ]
1 [ [] [] [] [] ...... [] ]
2 [ [] [] [] [] ...... [] ]
     .
     .
     .

I wanted to know what is the Pythonic way of doing this.

Thanks a lot.

Two dimensional array as List of list is fine, only problem in it is that you must not use * operation to produce the lines from values, as that produces reference to same value. You seem to be actually planning three dimensional array as in your example you have list value as value in list of list.

If you have two dimensions, like you seem to refer in text, here is example of multiplication table by the list comprehension producing list of lists:

table = [[a*b for b in range(17)] for a in range(17)]

Thanks PyTony. What you suggest is more or less what I had in mind and the reason I posted this was to ensure that there is no better way of implementing this in Python.

Thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.