Introducci贸n

1

El Zen de Python

Conjuntos

2

Sets

3

Modificando conjuntos

4

Operaciones con conjuntos

5

Playgrounds: Elimina elementos duplicados usando conjuntos

Comprehensions

6

List Comprehension

7

Dictionary Comprehension

8

Dictionary Comprehension: condition

9

Playgrounds: Crea una lista usando List Comprehension

10

Lists vs. Tuples vs. Sets

Funciones

11

Funciones

12

Funciones: return

13

Par谩metros por defecto y m煤ltiples returns

14

El scope

15

Refactor game

16

Playgrounds: Tienda de Tecnolog铆a

17

Funciones an贸nimas: lambda

18

Higher order function: una funci贸n dentro de otra funci贸n

19

Map

20

Map con diccionarios

21

Reto: map con inmutabilidad

22

Playgrounds: Multiplica todos los elementos por dos

23

Filter

24

Playgrounds: Retorna solo palabras de 4 letras y m谩s

25

Reduce

M贸dulos

26

M贸dulos

27

Mis propios m贸dulos

28

M贸dulos como scripts: __name__ y __main__

29

Paquetes

30

Playgrounds: Calcular la suma de todas las compras

Manipulaci贸n de archivos y errores

31

Iterables

32

Errores en Python

33

Manejo de excepciones

34

Playgrounds: Captura la excepci贸n: ZeroDivisionError

35

Leer un archivo de texto

36

Escribir en un archivo

37

Leer un CSV

38

Playgrounds: Lee un CSV para calcular el total de gastos

Gr谩ficas en Python

39

Creando una gr谩fica

40

Reto: graficando la poblaci贸n de un pa铆s

41

Reto: graficando la poblaci贸n mundial

Pr贸ximos pasos

42

隆Conoce otros proyectos de este curso!

43

Reconoce tu proceso y certif铆cate

44

Toma el Curso de PIP y Entornos Virtuales con Python

No tienes acceso a esta clase

隆Contin煤a aprendiendo! 脷nete y comienza a potenciar tu carrera

Playgrounds: Crea una lista usando List Comprehension

9/44

Aportes 252

Preguntas 4

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

Esta es la soluci贸n que realice para este desaf铆o:

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [number for number in numbers if number % 2 == 0]

print('v2 =>', even_numbers_v2)

Es un gran logro para mi que me resulte a al primera, esto porque he tenido muchas dificultades de tiempo y no he conseguido tomar clases seguido, por tal raz贸n, recordar la sintaxis y dem谩s me es muy significativo a nivel personal.

Cada vez entendiendo mas

even_numbers_v2 = [number for number in numbers if number % 2 == 0]

Esta es mi soluci贸n, abierto a sugerencias.
numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
if number % 2 == 0:
even_numbers.append(number)
print('v1 => ', even_numbers)

Ahora usando List Comprehension 馃憞

even_numbers_v2 = [i*1 for i in numbers if i%2==0 ]

print('v2 => ', even_numbers_v2)

```python numbers = [35, 16, 10, 34, 37, 25] even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) print('v1 =>', even_numbers) # Ahora usando List Comprehension 馃憞 even_numbers_v2 = [odd for odd in numbers if odd%2 == 0] print('v2 =>', even_numbers_v2) ```
Hola, la soluci贸n me qued贸 de la siguiente manera: `numbers = [35, 16, 10, 34, 37, 25]` `even_numbers2 = [i for i in numbers if i%2 == 0]` `print('v2=>', even_numbers2)`
me sigo sorprendiendo que la manera para saber si un numero es par o impar es saber si el residuo es 0 con % antes de estos cursos nunca lo hubiera pensado asi
Mi soluci贸n: ```python even_numbers_v2 = [i for i in numbers if i % 2 == 0] print('v2 =>', even_numbers_v2) ```v2 => \[16, 10, 34]
```js even_numbers_v2 = [number for number in numbers if number % 2 == 0] ```even\_numbers\_v2 = \[number for number in numbers if number % 2 == 0]
![](https://static.platzi.com/media/user_upload/image-841bc77e-d5e4-462a-a1a6-742a80460cbb.jpg)
\#Mi respuesta ![](https://static.platzi.com/media/user_upload/image-874bded3-2e9b-4a84-b3d0-6d7153ab7d52.jpg)
Mi respuesta: ![](https://static.platzi.com/media/user_upload/image-a1074d81-e5b0-4384-9dd5-0401fd2cbba3.jpg)
```js numbers = [35, 16, 10, 34, 37, 25] even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) print('v1 =>', even_numbers) # Ahora usando List Comprehension 馃憞 even_numbers_v2 = [number for number in numbers if number % 2 == 0] print('v2 =>', even_numbers_v2) ```
Ya me estaba enredando con el reto y me estaba estresando. Jajaja. Pero bueno, logr茅 entender el problema, estaba confundido con el ***even\_numbers = \[]*** y no sab铆a c贸mo meterlo dentro del c贸digo final. Siento que en la clase de ***List Comprehension*** falt贸 hacer m谩s ejercicios para entender mejor c贸mo funciona. Despu茅s de varios intentos, mi c贸digo finalmente qued贸 as铆: ```python even_numbers_v2 = [number for number in numbers if number % 2 == 0] print('v2 =>', even_numbers_v2) ```驴Qu茅 significa ese c贸digo? 1. number **for** number **in** numbers: Esa es la expresi贸n que m谩s me confund铆a. Lo que se est谩 haciendo es generar un bucle, ese bucle recorrerr谩 todos los valores que nos entregaron en la variable : ***numbers.*** 2. number: esa varibale es una varibale temporal, all铆 se alojar谩 el resultado del bucle y luego se a帽adir谩 a la variable fija que se solicita en el ejercicio: even\_numbers\_v2. 3. Por 煤ltimo, if number % 2 == 0: ES la condici贸n que se le aplica a la cariable para que me arroje un resultado esperado.
![](https://static.platzi.com/media/user_upload/image-2e2fbe71-6119-4cb8-9a65-89ee74106f00.jpg)
```python even_numbers_v2 = [number for number in numbers if number % 2 == 0] print('v2 => ', even_numbers_v2) ```
```python even_numbers_v2 = [number for number in numbers if number % 2 == 0 ] print('v2 =>', even_numbers_v2) ```
even\_numbers\_v2 = \[number for number in numbers if number % 2 == 0]
![](https://static.platzi.com/media/user_upload/image-d80e6cfa-aae6-42f8-b0d7-a9494cacb807.jpg)
![](https://static.platzi.com/media/user_upload/imagen-4beab885-4271-4775-9412-ae64353ef366.jpg)
```js numbers = [35, 16, 10, 34, 37, 25] even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) print('v1 =>', even_numbers) # Ahora usando List Comprehension 馃憞 even_numbers_v2 = [number for number in numbers if number % 2 == 0] print('v2 =>', even_numbers_v2) ```numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[]for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number)print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[number for number in numbers if number % 2 == 0] print('v2 =>', even\_numbers\_v2)
![](https://static.platzi.com/media/user_upload/image-a48a8e69-84f3-4ab1-95da-c18fbe0570f9.jpg)
```python numbers = [35, 16, 10, 34, 37, 25] even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) print('v1 =>', even_numbers) # Ahora usando List Comprehension 馃憞 even_numbers_v2 = [] even_numbers_v2 = [number for number in numbers if number % 2 == 0 ] print('v2 =>', even_numbers_v2) ```
mi humilde solucion even\_numbers = \[]for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number)print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[number for number in numbers if number % 2 == 0] print('v2 =>', even\_numbers\_v2)
Estoy complementando todo lo que vemos aqu铆 en Platzi con un curso en Youtube, me sirve de repaso y estoy entendiendo mucho mejor todo. Es como dice Freddy, la curva de mi aprendizaje se hace menos pesada.
![](https://static.platzi.com/media/user_upload/image-15c6d39a-6be0-44bc-9e87-8fb4cf3bb3c1.jpg)
`numbers = [35, 16, 10, 34, 37, 25]` `even_numbers = []` `for number in numbers:` ` if number % 2 == 0:` ` even_numbers.append(number)` `print('v1 =>', even_numbers)` `# Ahora usando List Comprehension 馃憞` `even_numbers_v2 = [ number for number in numbers if number%2==0]` `print('v2 =>', even_numbers_v2)`
![](https://static.platzi.com/media/user_upload/image-26031fc7-b323-4169-a3b1-02a261c5d989.jpg)
Listo: ![](https://static.platzi.com/media/user_upload/Screenshot%20from%202024-03-23%2013-38-12-838f882a-770d-47a0-b5b9-f253add8d0f7.jpg)
`<numbers = [35, 16, 10, 34, 37, 25]` `# M茅todo tradicional para obtener n煤meros pares` `even_numbers = []` `for number in numbers: # Para cada n煤mero en la lista de n煤meros` ` if number % 2 == 0: # Si el n煤mero es par` ` even_numbers.append(number) # Agregar el n煤mero a la lista de n煤meros pares` `print('v1 =>', even_numbers) # Imprimir la lista de n煤meros pares obtenida` `# Utilizando List Comprehension para obtener n煤meros pares` `even_numbers_v2 = [number for number in numbers if number % 2 == 0] # Lista de comprensi贸n: para cada n煤mero en la lista, si es par, agregarlo a la lista de n煤meros pares` `print('v2 =>', even_numbers_v2) # Imprimir la lista de n煤meros pares obtenida mediante List Comprehension `
![](https://static.platzi.com/media/user_upload/image-a3a080b0-7692-4cf7-a8d7-d947c39e801a.jpg)
adjunto mi resoluci贸n: ![](https://static.platzi.com/media/user_upload/image-caf2af0f-ed17-4276-b14d-ba1b06fa2d6f.jpg)
Mi aporte : ![](https://static.platzi.com/media/user_upload/image-8c98af85-12a9-432d-9948-59374025582d.jpg)
numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[]for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number)print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[number for number in numbers if number %2 == 0] print('v2 =>', even\_numbers\_v2)
Listo
![](https://static.platzi.com/media/user_upload/image-a4715f6d-6930-454b-8680-02863ea8427a.jpg)![](https://static.platzi.com/media/user_upload/image-bd8de8da-9dd4-4e5c-a50e-c0b58aafb747.jpg)
![](https://static.platzi.com/media/user_upload/imagen-4b5c15b6-66a1-4adf-8ee1-d5fa9cf847fc.jpg)
```js even_numbers_v2 = [number for number in numbers if number % 2 == 0] ```even\_numbers\_v2 = \[number for number in numbers if number % 2 == 0]
Pueden realizar la prueba tambi茅n en replit, as铆 verifican el resultado, que en este caso deber铆an ser (16, 10, 34)
![](https://static.platzi.com/media/user_upload/image-abeed40c-60f1-4b80-9116-e2eb11054262.jpg)
![](https://static.platzi.com/media/user_upload/image-8fc293e1-063f-4e24-bac7-b9f4e33bcdb6.jpg)
numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[]for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number)print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[]even\_numbers\_v2 = \[number for number in numbers if number %2 == 0] print('v2 =>', even\_numbers\_v2)
![](file:///C:/Users/JUDADBAL/OneDrive%20-%20Anheuser-Busch%20InBev/My%20Pictures/1.PNG)

馃捇馃煝 Saludos platzinautas.
La soluci贸n es simple y legible gracias a los 鈥渓ist comprehension鈥:

even_numbers_v2 = [number for number in numbers if number %2 == 0]
print('v2 =>', even_numbers_v2)
![](https://static.platzi.com/media/user_upload/image-4a220a40-5fc5-4c2d-bd9b-e571cd819487.jpg)
numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[] for number in numbers:聽 if number % 2 == 0: even\_numbers.append(number) print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞 even\_numbers\_v2 = \[number for number in numbers if number % 2 == 0] print('v2 =>', even\_numbers\_v2)
``` even\_numbers\_v2 = \[n for n in numbers if n % 2 == 0] ```
numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[]for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number)print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[]even\_numbers\_v2 = \[ i 聽for 聽i in numbers if 聽i % 2 == 0]print (even\_numbers\_v2)print('v2 =>', even\_numbers\_v2)
![](https://static.platzi.com/media/user_upload/image-5df56ab8-e412-4874-9c98-09619467110c.jpg)
El c贸digo que nos piden est谩 en la l铆nea 11 ![](https://static.platzi.com/media/user_upload/image-a1e12db1-9338-42b4-b559-bb6442aee24b.jpg)
Buenas, les dejo mi soluci贸n, espero sea se ayuda, saludos: numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[]for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number)print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[number for number in numbers if number % 2 == 0] print('v2 =>', even\_numbers\_v2)
Despu茅s de repasar por mas de 1 hora los ejemplos de las clases anteriores me di cuenta que estaba poniendo mal el orden de las variables pero por fin lo logre ![](https://static.platzi.com/media/user_upload/image-3e68ccfa-79af-4576-bbcb-46be6abf2d30.jpg)

Soluci贸n:

even_numbers_v2 = [ number for number in numbers if number % 2 == 0]

Aca tengo mi ejemplo donde tambien extraemos los numeros impares!

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [numeros for numeros in numbers if numeros % 2 == 0]

even_numbers_v3 = [numeros for numeros in numbers if numeros % 2 != 0]

print('v2 =>', even_numbers_v2)
print('v3 =>', even_numbers_v3)
numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[]for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number)print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[ number for number in numbers if number % 2 == 0]聽print('v2 =>', even\_numbers\_v2)
```python numbers = [35, 16, 10, 34, 37, 25] even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) print('v1 =>', even_numbers) # Ahora usando List Comprehension 馃憞 even_numbers_v2 = [number for number in numbers if number % 2 == 0] print('v2 =>', even_numbers_v2) ```

Mi soluci贸n

even_numbers_v2 = [number for number in numbers if number % 2 == 0]

print('v2 =>', even_numbers_v2)

Me gusto el ejercicio y como este se llega a implementar en nusetro codigo. Me alegra seguir aprendiendo en python. Sere uno de los mejores.

```python numbers = [35, 16, 10, 34, 37, 25] even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) print('v1 =>', even_numbers) even_numbers_v2 = [i for i in numbers if i % 2 == 0] print('v2 =>', even_numbers_v2) ```Estoy repitiendo este curso por q me hab铆an quedado muchas dudas, ahora lo puedo entender mucho mejor.

Increible鈥
por un momento pense que no sabia, pero ahora ya se.

```python numbers = [35, 16, 10, 34, 37, 25] even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) print('v1 =>', even_numbers) # Ahora usando List Comprehension 馃憞 even_numbers_v2 = [number for number in numbers if number % 2 == 0] print('v2 =>', even_numbers_v2) ```
Os dejo una posible soluci贸n: even\_numbers\_v2 = \[n for n in numbers if n % 2 == 0] print('v2 =>', even\_numbers\_v2)
`#Crea una lista usando List Comprehension` `numbers = [35, 16, 10, 34, 37, 25]` `even_numbers = []` `for number in numbers:聽 ` `if number % 2 == 0:聽 聽 ` `even_numbers.append(number)` `print('v1 =>', even_numbers)` `# Soluci贸n 馃憞` `even_numbers_v2 = [number for number in numbers if number % 2 == 0]` `print('v2 =>', even_numbers_v2)`
numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [number for number in numbers if number % 2 == 0]

print('v2 =>', even_numbers_v2)
![](https://static.platzi.com/media/user_upload/image-9963cbac-83c2-4e56-a42a-d4cb5601ed25.jpg)
even\_numbers\_v2 = \[number for number in numbers if number % 2 == 0]

reto cumplido

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [number for number in numbers if number % 2 == 0]

print('v2 =>', even_numbers_v2)```
```js numbers = [35, 16, 10, 34, 37, 25] even_numbers = [] for number in numbers: if number % 2 == 0: even_numbers.append(number) print('v1 =>', even_numbers) # Ahora usando List Comprehension 馃憞 even_numbers_v2 = [item for item in numbers if item %2==0] print('v2 =>', even_numbers_v2) ```numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[]for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number)print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[item for item in numbers if item %2==0] print('v2 =>', even\_numbers\_v2)
tal vez esto ayude. ![](https://static.platzi.com/media/user_upload/image-2b0e6037-7c56-424a-b76e-f1d7d309cba5.jpg)![](https://static.platzi.com/media/user_upload/image-8b784ab6-8ef0-4859-892d-064878bb3a65.jpg)
![](https://static.platzi.com/media/user_upload/image-4b2ecee9-c1e0-481b-b1d0-3324d123857a.jpg)
numbers = \[35, 16, 10, 34, 37, 25] even\_numbers\_v2 = \[serie for serie in numbers if serie % 2 == 0] print('v2 =>', even\_numbers\_v2) me funciono al pelo :-)
even_numbers_v2 = [number for number in numbers if number % 2 == 0]

Mi aporte.! numbers = \[35, 16, 10, 34, 37, 25] even\_numbers = \[] for number in numbers:聽 if number % 2 == 0:聽 聽 even\_numbers.append(number) print('v1 =>', even\_numbers) \# Ahora usando List Comprehension 馃憞even\_numbers\_v2 = \[i for i in numbers if i % 2 == 0] print('v2 =>', even\_numbers\_v2)

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
if number % 2 == 0:
even_numbers.append(number)
print(鈥榲1 =>鈥, even_numbers)

Ahora usando List Comprehension 馃憞

even_numbers_v2 = [number for number in numbers if number % 2 == 0]

print(鈥榲2 =>鈥, even_numbers_v2)

As铆 qued贸 mi c贸digo:


Les dejo mi aporte

numbers = [35, 16, 10, 34, 37, 25]
even_numbers = []
for number in numbers:
if number % 2 == 0:
even_numbers.append(number)
print(鈥榲1 =>鈥, even_numbers)

respuesta deirecta y sencilla

even_numbers_v2 = [number for number in numbers if number % 2 == 0]
print(鈥榲2 =>鈥, even_numbers_v2)

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers) 

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [number for number in numbers if number % 2 == 0]
 
print('v2 =>', even_numbers_v2) 

Resultado
v1 => [16, 10, 34]
v2 => [16, 10, 34]

Hola a todos! Esta es la linea que agregue para la soluci贸n:

even_numbers_v2 = [n for n in numbers if n % 2 == 0]

Mi soluci贸n, me sali贸 a la primera, creo que por ahora he aprendido de una manera sobresaliente y siento que voy por buen camino.

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
if number % 2 == 0:
even_numbers.append(number)
print(鈥榲1 =>鈥, even_numbers)

Ahora usando List Comprehension 馃憞

even_numbers_v2 = [number for number in numbers if number % 2 == 0]

print(鈥榲2 =>鈥, even_numbers_v2)

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
if number % 2 == 0:
even_numbers.append(number)
print(鈥榲1 =>鈥, even_numbers)

Ahora usando List Comprehension 馃憞

even_numbers_v2 = [numero for numero in numbers if numero % 2 ==0 ]

print(鈥榲2 =>鈥, even_numbers_v2)

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [number for number in numbers if number%2==0]

print('v2 =>', even_numbers_v2)
numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [number for number in numbers if number % 2 == 0]

print('v2 =>', even_numbers_v2)

hola es dif铆cil no me da a la primera

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = list({number: number for number in numbers if(number % 2 == 0)})

print('v2 =>', even_numbers_v2)

mi aporte

Me siento re feliz cuando acierto los playgrounds 馃榿, por cierto, las list comprehension son lo mismo de un ciclo for pero en una sola l铆nea. Aqu铆 mi soluci贸n


.
.
.
.
.
.
.
.
.

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [i for i in numbers if i % 2 == 0]

print('v2 =>', even_numbers_v2)

Esta fue mi solucion:

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞

even_numbers_v2 = [x for x in numbers if x % 2 == 0]
print('v2 =>', even_numbers_v2)

)

even_numbers_v2 = [ number for number in numbers if number % 2 == 0 ]
v1 => [16, 10, 34]

v2 => [16, 10, 34]

Listo !

TRADICIONAL

numbers = [35, 16, 10, 34, 37, 25]
even_numbers_v1 = []
for number in numbers:
if number % 2 == 0:
even_numbers_v1.append(number)
print(鈥榁ERSI脫N 1 =>鈥,even_numbers_v1)

COMPREHENSION

even_numbers_v2 = [number for number in numbers if number % 2 == 0]
print(鈥榁ERSI脫N 2 =>鈥,even_numbers_v2)

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

# Ahora usando List Comprehension 馃憞
even_numbers_v2 = [number for number in numbers if number%2==0]

print('v2 =>', even_numbers_v2)


.
.
.
.
.

numbers = [35, 16, 10, 34, 37, 25]

even_numbers = []
for number in numbers:
  if number % 2 == 0:
    even_numbers.append(number)
print('v1 =>', even_numbers)

even_numbers_v2 = []
even_numbers_v2 = [number for number in numbers if number % 2 == 0]

print('v2 =>', even_numbers_v2)
undefined