-
Notifications
You must be signed in to change notification settings - Fork 1
Lists
Jean Dubois edited this page Jun 25, 2024
·
15 revisions
In Nougaro, Lists work like in Python:
-
[]
is an empty list -
[1, 2, "helloworld"]
is a list with some elements. - A list can contain every types of elements (numbers, strings, lists...)
- To create a list with elements from another list (and other elements), you can use this syntax:
var list_ = [3, 4] ; print([1, 2, *list_, 5])
prints[1, 2, 3, 4, 5]
.
- You can add elements to lists:
[1, 2, 'str'] + '3'
=[1, 2, 'str', 3]
. Can be done withappend([1, 2, 'str'], 3)
- Extend lists with multiplication:
[1, 2, 'str'] * [3, 4, 'str2']
=[1, 2, 'str', 3, 4, 'str2']
. Can be done withextend([1, 2, 'str'], [3, 4, 'str2'])
- Extend lists with theirselves using multiplication with integers:
[0]*3
=[0, 0, 0]
;["a", None]*2
=["a", None, "a", None]
- Get one element with division:
[1, 2, 'str'] / 0
=1
,[1, 2, 'str'] / -1
='str'
- Get one or more elements with call:
[0, 1, 2, 3, 4](3, -2)
=[3, 3]
- Pop elements with substraction:
[1, 2, 'str'] - 0
=[2, 'str']
,[1, 2, 'str'] - -1
=[1, 2]
. Can be done withpop([1, 2, 'str'], 0)
(but returns the element popped) - Insert elements with
insert(list, value, index)
. - Replace elements with
replace(list, index, value)
.