0

I need a data structure in python that can handle data like this in C:

typedef struct lp {
    char pvid[16];
    int ppnum;
} lp_t;

lp_t lpList[100000][3];

Basically, I read in a line, process it, and stuff it to an array lpList[lp#][copy#] for the particular physical partition on a disk. Can you help?

  • Merely add a list to a list, try it. – bipll Mar 01 '18 at 15:22
  • Possible duplicate of [How to define a two-dimensional array in Python](https://stackoverflow.com/questions/6667201/how-to-define-a-two-dimensional-array-in-python) – Mohamd Ali Mar 01 '18 at 17:40

1 Answers1

0

You can define your array as below:

array = []

width = 2
height = 2
array = []
for i in range(height):
    row=[]
    for j in range(width):
        row.append(0)
    array.append(row)

In the example above, you will have an array of 2 by 2 initialise with zeros. If you want to change a value, you can just do:

array[1][1] = 10
Liky
  • 1,105
  • 2
  • 11
  • 32