+ 1
Lambda
I want to see an example with function lambda with list . Maybe it have a map - function.
17 Respuestas
+ 2
Petr are you talking about this ?
print(list(map(lambda x:x if x%21==1 else "",(i for i in range(1,100)))))
If yes, it's not an appropriate choice if you only want the element that satisfies the condition ,filter function can help you in that case
print(list(filter(lambda x:x%21==1,(i for i in range(1,100)))))
+ 3
Abhay result must be spcm, and your result is ["s""p""c""m"].
But your example is perfect for me thanks!
+ 3
Oma Falk. :)) i want understand lambda and map. It is difficult for me in case, when i use more then two variables
+ 3
Petr right.. it will help if you learn further languages!
especially functional programming.
+ 3
Which Lambda are you referring to? Is it the one related with Physics calculations?
+ 2
For example, I have a list of strings and i want in one line write function for search the max string of it with repalce one char to other ("a" replace "o")
+ 2
Something like this ?
a=["foo","spam"]
print(list(map(lambda x:"c" if x=="a" else x,max(a))))
+ 2
Abhay and if i want get list of range for only elements%21=1?
+ 2
Abhay you are the BEST!!! Thank you!
+ 2
Mirielle[ InAcTiVe ] may be you have example of so combination map and iter-function?
+ 2
Oladimeji Abd'Rahman lambda is a special function in python https://www.sololearn.com/learn/Python/2460/
0
You can use join method of string to get output as spcm
print("".join(list(map(lambda x:"c" if x=="a" else x,max(a)))))
0
Hello,
you can use a lambda function in a Python list comprehension as follows:
>>> [(lambda x:x*x)(x) for x in range(1,4)]
[1, 4, 9]
But there is no point in doing so when the comprehension essentially gives you the lambda for free (you simply write the expression that would have been in the body of the lambda:
>>> [x*x for x in range(1,4)]
[1, 4, 9]
I hope this will help to you :)
0
x = int(input())
y = (lambda z:z*z*z)(x)
print(y)
0
y=(lambda z:z**3)(x)