DEV Community

Cristian Fernando
Cristian Fernando

Posted on

Ibuprofeno.py💊| #142: Explica este código Python

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)
Enter fullscreen mode Exit fullscreen mode
  • 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.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more