DEV Community

Cristian Fernando
Cristian Fernando

Posted on

1

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

Explica este código Python

Dificultad: Intermedio

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

res_map = list(map(lambda x: (x**2)/2, lista))
print(res_map)
Enter fullscreen mode Exit fullscreen mode
  • A. [3.0, 3.5, 4.0, 4.5, 5.0]
  • B. [18.0, 24.5, 32.0, 40.5, 50.0]
  • C. [36, 49, 64, 81, 100]
  • D. Ninguno de los anteriores

Respuesta:

👉 B. [18.0, 24.5, 32.0, 40.5, 50.0]

Python es un lenguaje de programación multi paradigma, nos permite usar funciones típicas de este paradigma como map(), filter() y reduce().

map() permite ejecutar una función en cada item de un iterable, en nuestro ejemplo, aplicamos (x**2)/2 a cada valor de la lista lista.

Para una sintaxis mas clara usamos una función lambda.

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

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay