Lists · Listas
| English | Español |
|---|---|
| list/lɪst/ | lista |
| elements/ˈelɪmənts/ | elementos |
| ordered collection/ˈɔːdəd kəˈlekʃn/ | colección ordenada |
| index/ˈɪndeks/ | índice |
| traverse/trəˈvɜːs/ | recorrer |
| general/ˈdʒenərəl/ | general |
| append/əˈpend/ | anexar |
A list holds many elements
- A list 列表 stores an ordered collection 有序集合 of values, called elements 元素, under one name.
- A single list
coloursmight hold "red", "green", and "blue". - One name replaces many separate variables.
- The order is fixed, so each element has a definite position.
Una lista contiene muchos elementos
- Una lista 列表 almacena una colección ordenada 有序集合 de valores, llamados elementos 元素, bajo un solo nombre.
- Una única lista
colourspodría contener "red", "green" y "blue". - Un solo nombre reemplaza a muchas variables separadas.
- El orden es fijo, por lo que cada elemento tiene una posición definida.
A list stores: · Una lista almacena:
Many values, one name, in a fixed order. · Muchos valores, un nombre, en un orden fijo.
Access by index
- You access or change an element using its index 索引 — its position in the list.
- In many languages the first element is at index $0$:
colours[0]is "red". - Read
colours[1]to get "green", or assign tocolours[2]to change it. - Always check where a language starts counting.
Acceso por índice
- Para acceder o modificar un elemento se utiliza su índice 索引 —su posición en la lista—.
- En muchos lenguajes, el primer elemento está en el índice $0$:
colours[0]es "red". - Lee
colours[1]para obtener "green", o asígnale un valor acolours[2]para cambiarlo. - Verifica siempre dónde comienza la numeración en tu lenguaje.
Access an element, or change the list? · ¿Acceder a un elemento o modificar la lista?
Reading colours[1] accesses an element; append, insert, and remove change the list's contents. · Leer colores[1] accede a un elemento; append, insert y remove modifican el contenido de la lista.
If lists start at index 0, colours[0] in ["red","green","blue"] is: · Si las listas comienzan con el índice 0, colores[0] en ["red","green","blue"] es:
Index 0 is the first element, "red". · El índice 0 es el primer elemento, "red".
Visiting every element of a list in turn with a loop is called ______ the list. · Visitar cada elemento de una lista por turno con un bucle se llama ______ la lista.
Traversal processes the whole list, whatever its size. · La traversación procesa toda la lista, sin importar su tamaño.
Traverse with a loop
- To process a whole list, use iteration to traverse 遍历 it.
- A loop visits every element in turn — first, second, third, and so on.
- The same loop works no matter how many elements the list holds.
- This is what makes list code so general 通用.
Recorre con un bucle
- Para procesar toda una lista, usa iteración para recorrerla 遍历.
- Un bucle visita cada elemento sucesivamente: primero, segundo, tercero, etcétera.
- El mismo bucle funciona sin importar cuántos elementos tenga la lista.
- Esto es lo que hace que el código de listas sea tan genérico 通用.
The append operation: · La operación append:
Append grows the list by one at the end. · Append hace crecer la lista en uno al final.
Traversing [70, 85, 90] and adding each to a total gives what final total? · Recorrer [70, 85, 90] y sumar cada uno a un total da ¿cuál total final?
70 + 85 + 90 = 245.
The same traversal loop works whether the list has 3 elements or 300. · El mismo bucle de recorrido funciona ya sea que la lista tenga 3 elementos o 300.
The loop refers to the list by name, making it general. · El bucle hace referencia a la lista por nombre, haciéndolo general.
Change the contents
- Lists support operations that change their contents:
- append 追加 adds a new element to the end;
- insert adds an element at a chosen position; remove takes one out.
Total a list. scores holds [70, 85, 90]. Start total ← 0, then traverse: 70 → total 70; 85 → total 155; 90 → total 245. Final total 245. Append a fourth score and the same loop adds it too — no code change.
Modificar el contenido
- Las listas soportan operaciones que modifican su contenido:
- append 追加 añade un nuevo elemento al final;
- insert añade un elemento en una posición elegida; remove elimina uno.
Suma los elementos de una lista. scores contiene [70, 85, 90]. Inicia total ← 0, luego recorre: 70 → total 70; 85 → total 155; 90 → total 245. Total final 245. Añade una cuarta puntuación y el mismo bucle también la sumará —sin necesidad de cambiar el código—.
A list is an ordered collection of elements under one name, reached by index (often from 0). Traverse it with a loop to process every element, which keeps code general for any size. Lists also change: append, insert, and remove.
Una lista es una colección ordenada de elementos bajo un solo nombre, a la que se accede mediante un índice (generalmente desde 0). Recórrela con un bucle para procesar cada elemento, lo que mantiene el código genérico para cualquier tamaño. Las listas también son mutables: permiten append, insert y remove.