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)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay