Skip to content

Commit

Permalink
Merge pull request #2368 from eduardoxfurtado/master
Browse files Browse the repository at this point in the history
Updated documentation to make it clear how to use multidimensional lists
  • Loading branch information
fubuloubu authored Jul 24, 2021
2 parents 6e7dba7 + 9693d81 commit cbc9e65
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion docs/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Fixed-size Lists

Fixed-size lists hold a finite number of elements which belong to a specified type.

Lists can be declared with ``_name: _ValueType[_Integer]``. Multidimensional lists are also possible.
Lists can be declared with ``_name: _ValueType[_Integer]``.

.. code-block:: python
Expand All @@ -387,6 +387,24 @@ Lists can be declared with ``_name: _ValueType[_Integer]``. Multidimensional lis
# Returning a value
return exampleList[0]
Multidimensional lists are also possible. The notation for the declaration is reversed compared to some other languages, but the access notation is not reversed.

A two dimensional list can be declared with ``_name: _ValueType[inner_size][outer_size]``. Elements can be accessed with ``_name[outer_index][inner_index]``.

.. code-block:: python
# Defining a list with 2 rows and 5 columns and set all values to 0
exampleList2D: int128[5][2] = empty(int128[5][2])
# Setting a value for row the first row (0) and last column (4)
exampleList2D[0][4] = 42
# Setting values
exampleList2D = [[10, 11, 12, 13, 14], [16, 17, 18, 19, 20]]
# Returning the value in row 0 column 4 (in this case 14)
return exampleList2D[0][4]
.. _types-struct:

Structs
Expand Down

0 comments on commit cbc9e65

Please sign in to comment.