Contenido del Curso
Estructuras de Datos en Python
Estructuras de Datos en Python
Las Listas son Mutables
Las listas son una estructura de datos flexible en Python, lo que significa que puedes modificarlas añadiendo, eliminando o cambiando elementos. Además, puedes reemplazar un único elemento por varios.
numbers = [2, 14, 16, 32, 24, 65, 75] # Replacement of the fourth element numbers[3] = 5 print(numbers)
In this example:
- We replaced the city "New York" at index 3 with "Rome";
- Using negative indexing, we replaced the last two cities ("Rome" and "Sydney") with "Dubai" and "Cape Town".
You can also make multiple changes in one step:
cities = ["Paris", "Tokyo", "New York", "Berlin", "Sydney"] # Replacing multiple cities in the middle cities[1:3] = ["Seoul", "Bangkok", "Mumbai"] print(cities) # Output: ['Paris', 'Seoul', 'Bangkok', 'Mumbai', 'Berlin', 'Sydney']
Here, we replaced "Tokyo" and "New York" with three cities: "Seoul", "Bangkok", and "Mumbai". This demonstrates how flexible list mutability can be for managing your data.
Tarea
You're working with the list [2, 4, 8, 64, 1024]
. Your task is to update the last item to 5
and the first item to 0
.
¡Gracias por tus comentarios!
Las Listas son Mutables
Las listas son una estructura de datos flexible en Python, lo que significa que puedes modificarlas añadiendo, eliminando o cambiando elementos. Además, puedes reemplazar un único elemento por varios.
numbers = [2, 14, 16, 32, 24, 65, 75] # Replacement of the fourth element numbers[3] = 5 print(numbers)
In this example:
- We replaced the city "New York" at index 3 with "Rome";
- Using negative indexing, we replaced the last two cities ("Rome" and "Sydney") with "Dubai" and "Cape Town".
You can also make multiple changes in one step:
cities = ["Paris", "Tokyo", "New York", "Berlin", "Sydney"] # Replacing multiple cities in the middle cities[1:3] = ["Seoul", "Bangkok", "Mumbai"] print(cities) # Output: ['Paris', 'Seoul', 'Bangkok', 'Mumbai', 'Berlin', 'Sydney']
Here, we replaced "Tokyo" and "New York" with three cities: "Seoul", "Bangkok", and "Mumbai". This demonstrates how flexible list mutability can be for managing your data.
Tarea
You're working with the list [2, 4, 8, 64, 1024]
. Your task is to update the last item to 5
and the first item to 0
.
¡Gracias por tus comentarios!
Las Listas son Mutables
Las listas son una estructura de datos flexible en Python, lo que significa que puedes modificarlas añadiendo, eliminando o cambiando elementos. Además, puedes reemplazar un único elemento por varios.
numbers = [2, 14, 16, 32, 24, 65, 75] # Replacement of the fourth element numbers[3] = 5 print(numbers)
In this example:
- We replaced the city "New York" at index 3 with "Rome";
- Using negative indexing, we replaced the last two cities ("Rome" and "Sydney") with "Dubai" and "Cape Town".
You can also make multiple changes in one step:
cities = ["Paris", "Tokyo", "New York", "Berlin", "Sydney"] # Replacing multiple cities in the middle cities[1:3] = ["Seoul", "Bangkok", "Mumbai"] print(cities) # Output: ['Paris', 'Seoul', 'Bangkok', 'Mumbai', 'Berlin', 'Sydney']
Here, we replaced "Tokyo" and "New York" with three cities: "Seoul", "Bangkok", and "Mumbai". This demonstrates how flexible list mutability can be for managing your data.
Tarea
You're working with the list [2, 4, 8, 64, 1024]
. Your task is to update the last item to 5
and the first item to 0
.
¡Gracias por tus comentarios!
Las listas son una estructura de datos flexible en Python, lo que significa que puedes modificarlas añadiendo, eliminando o cambiando elementos. Además, puedes reemplazar un único elemento por varios.
numbers = [2, 14, 16, 32, 24, 65, 75] # Replacement of the fourth element numbers[3] = 5 print(numbers)
In this example:
- We replaced the city "New York" at index 3 with "Rome";
- Using negative indexing, we replaced the last two cities ("Rome" and "Sydney") with "Dubai" and "Cape Town".
You can also make multiple changes in one step:
cities = ["Paris", "Tokyo", "New York", "Berlin", "Sydney"] # Replacing multiple cities in the middle cities[1:3] = ["Seoul", "Bangkok", "Mumbai"] print(cities) # Output: ['Paris', 'Seoul', 'Bangkok', 'Mumbai', 'Berlin', 'Sydney']
Here, we replaced "Tokyo" and "New York" with three cities: "Seoul", "Bangkok", and "Mumbai". This demonstrates how flexible list mutability can be for managing your data.
Tarea
You're working with the list [2, 4, 8, 64, 1024]
. Your task is to update the last item to 5
and the first item to 0
.