+ 3

A good way to create multidimensional arrays in python.

Multidimensional arrays don't seem to exist by default in Python like in other languages. So what is a good, pythonic way to create a N×N sized multidimensional list in python. For example, if N is 3, the list should be [[[], [], []], [[], [], []], [[], [], []]] You can view what I tried in this code of mine, about line 7 to 11 https://code.sololearn.com/cPBXqw3qDGqa/?ref=app But the way seems bad and unprofessional to me. What's a good, pythonic way to do the same?

18th Jul 2018, 4:05 AM
Satyam
4 odpowiedzi
18th Jul 2018, 6:14 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
Nope, just lists. Effectively, they can be used as arrays, but are more powerful (and less efficient), as they can store elements of mixed, any type of data, while arrays are monotyped.
18th Jul 2018, 7:36 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Thank you. numpy would work i guess but anything built in?
18th Jul 2018, 6:16 AM
Satyam
+ 1
hmmm... Thank you!
18th Jul 2018, 7:37 AM
Satyam