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
Cristian Fernando | Sciencx (2024-07-16T11:00:00+00:00) Ibuprofeno.py💊| #142: Explica este código Python. Retrieved from https://www.scien.cx/2024/07/16/ibuprofeno-py%f0%9f%92%8a-142-explica-este-codigo-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.