Ibuprofeno.pyπŸ’Š| #142: Explica este cΓ³digo Python



This content originally appeared on DEV Community and was authored by Cristian Fernando

Explica este cΓ³digo Python

Dificultad: Intermedio

lista = [6,7,8,9,10]

res_filter = list(filter(lambda x: x > 8 ,lista))
print(res_filter)
  • A. [9, 10]
  • B. [6, 7, 8, 9, 10]
  • C. [1, 2, 3, 4, 5, 6, 7]
  • D. [8, 9, 10]

Respuesta:

👉 A. [9, 10]

filter() se encarga de hacer un filtrado de un iterable, en nuestro ejemplo aplicamos la condiciΓ³n x > 8 a toda la lista lista, entonces regresamos una nueva lista que solo tenga los items que cumplan con la condiciΓ³n dada.


This content originally appeared on DEV Community and was authored by Cristian Fernando