[Tutor] Two dimensional lists

Phil phillor9 at gmail.com
Mon Nov 2 04:33:10 EST 2020


On 2/11/20 6:53 pm, Cameron Simpson wrote:
> You said you had some C++ code, so I'm going to provide some C code
> below to show some mechanism in a form I hope you're already familiar
> with.

OK Cameron thank you, I've got it now.

Declaring a two dimensional array in C takes one line of code, e.g. int 
b[5][5].

The equivalent in Python takes 7 lines or one long line:

b = [
     [0] * 5,
     [0] * 5,
     [0] * 5,
     [0] * 5,
     [0] * 5,
     ]

My array is [30] [25] which means many lines of code, something I want 
to avoid. Creating a numpy array is also one line of code.

Anyway Cameron I appreciate the time that you've devoted to this.

-- 

Regards,
Phil



More information about the Tutor mailing list