Search code examples
python-3.xpython-2.7subprocesspseudocode

How do I declare a 2d array in python?


enter image description here

How on earth do I declare this ? Using the code "temperature[6,2]" probably wouldn't work as it starts from 0

HELP!


Solution

  • There are lots of ways to do this. For static data I would do it this way

    temperature = [[6, 13, 5],
                   [5, 12, 6],
                   [9, 17, 8],
                   [9, 20, 9],
                   [7, 15, 6],
                   [6, 13, 6],
                   [7, 13, 6]]
    

    Note that what you are actually doing here is making a 'list of lists'

    >>> temperature[6]
    [7, 13, 6]
    
    >>> temperature[6][2]
    6