- 1). Declare an empty list. A "list" in Python represents a collection of data similar to an array, and will serve as your foundational list:
>>>my_array = list() - 2). Populate that list with other lists. In computer science, a multi-dimensional array represents a collection of collections. In this example, you will create a list of lists:
>>>my_array = [[1,2], [3,4], [5,6]] //a list containing 3 lists - 3). Create an empty three-dimensional array. This example declares "my_array" as an empty list of three lists, making it an empty three-dimensional array:
>>>my_array = [[], [], []] //a list of three empty lists - 4). Add to a list and read from it. Each list in the "my_array" list has its own array index; you can access each one individually to add and read data:
>>>my_array[1].append(2) //adds "2" to the second list (lists are zero-indexed)
>>>my_array
[[], [2], []]
>>>my_array[1]
[2]
SHARE