Listas
Una variable guarda una cosa. Una lista guarda todas las que quieras, en orden.
Lists
A variable holds one thing. A list holds as many as you want, in order.
Una lista va entre corchetes [ ], con los valores separados por comas. Pueden
ser de cualquier tipo, e incluso mezclarse.
A list goes between brackets [ ], values separated by commas. They can be of
any type, and even mixed.
Esas funciones —len, max, min,
sum— vienen incluidas. En otros lenguajes tendrías que escribir un bucle para cada
una.
Those functions — len, max,
min, sum — come built in. In other languages you would write a loop
for each.
Lo que más confunde al principio: el primer elemento es el número 0.
["Ana", "Joaco", "María"] 0 1 2 -3 -2 -1
Y Python tiene algo que casi ningún lenguaje ofrece: índices negativos. El
-1 es el último, sin importar cuántos elementos haya. Muy cómodo.
The most confusing thing at first: the first item is number 0.
["Ana", "Joaco", "María"] 0 1 2 -3 -2 -1
And Python has something almost no other language offers: negative indexes.
-1 is the last one, however many there are. Very handy.
Con dos puntos puedes sacar un pedazo de la lista. Se llama slicing y es una de las cosas más queridas de Python.
Se lee [desde:hasta], donde el "hasta" no se incluye.
With a colon you can take a chunk of the list. It is called slicing and it is one of Python's most loved features.
Read it as [from:to], where "to" is not included.
Las listas se pueden modificar. Estas son las operaciones que vas a usar siempre:
Lists can be modified. These are the operations you will always use:
Fíjate en "espada" in inventario: se lee como una frase
en inglés. Esa legibilidad es exactamente por lo que Python se recomienda tanto para empezar.
Note "espada" in inventario: it reads like an English
sentence. That readability is exactly why Python is so recommended for beginners.
Crear listas, len/max/min/sum, índices
positivos y negativos, slicing, y las operaciones para agregar, quitar y ordenar.
Ahora vamos a organizar el código con funciones.
Creating lists, len/max/min/sum,
positive and negative indexes, slicing, and the add, remove and sort operations.
Now let us organise the code with functions.