Skip to content

Lists and Matrices

Lists represent ordered collections of values. They can be declared with a specific type (lista<entero>) or without a type (lista).

// Typed list
lista<texto> nombres = ["Ana", "Carlos", "Maria"]
lista<entero> numeros = [1, 2, 3, 4, 5]
// Untyped list (can contain any type)
lista mixta = [1, "dos", verdadero, 3.14]
// Empty list
lista<entero> vacia = []

Lists are immutable unless indicated as variables with var.

lista<entero> var numeros = [3, 1, 4]
numeros.agregar(2) // Now: [3, 1, 4, 2]
  • Positive indices start at 0.
  • Negative indices access from the end (-1 is the last element).
lista<texto> frutas = ["manzana", "banana", "cereza"]
texto primera = frutas[0] // "manzana"
texto ultima = frutas[-1] // "cereza"
MethodDescriptionReturns
longitud()Number of elementsentero
esta_vacia()Checks if list has no elementslog
contiene(valor)Checks for value presencelog
MethodDescription
agregar(valor)Insert at end
insertar(indice, valor)Insert at specific position
remover(valor)Remove first occurrence
quitar_en(indice)Remove and return element at position
limpiar()Empty the list
MethodDescriptionReturns
buscar(valor)Position of first matchentero (-1 if not found)
buscar_ultimo(valor)Position of last matchentero
contar(valor)Number of occurrencesentero
MethodDescriptionModifies Original
ordenar()Sort ascendingYes
ordenar_descendente()Sort descendingYes
ordenado()Return sorted copyNo
invertir()Reverse orderYes
MethodDescription
sumar()Sum all elements
promedio()Calculate average
maximo()Get maximum value
minimo()Get minimum value
MethodDescription
concatenar(otra)Returns new combined list
extender(otra)Adds elements from another list
unir(delimitador)Concatenates elements as text

Matrices are lists of lists, allowing multidimensional data structures.

lista<lista<entero>> matriz_2d = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
// Access elements
entero valor = matriz_2d[1][2] // 6 (row 1, column 2)

Generates lists of consecutive integers.

lista<entero> del_cero = rango(5) // [0, 1, 2, 3, 4]
lista<entero> del_dos = rango(2, 7) // [2, 3, 4, 5, 6]