i try to write this function to lambda function,I tried a lot of options and I could not success:
def getitem_rlist(s, i):
while i > 0:
s, i = rest(s), i - 1
return first(s)
I know to begin with:
getitem_rlist=lambda s,i:....?
thanks!
in to example if: s=(1,(2,(3,4)))
then getitem_rlist(a,2))# -> 3
the function need to return the element at index i of recursive list s
Why Use Lambda Functions? Lambda functions are used when you need a function for a short period of time. This is commonly used when you want to pass a function as an argument to higher-order functions, that is, functions that take other functions as their arguments.
One of good alternatives of lambda function is list comprehension. For map() , filter() and reduce() , all of them can be done using list comprehension. List comprehension is a solution between a regular for-loop and lambda function.
How to replace lambda expression with method reference in Java 8. If you are using a lambda expression as an anonymous function but not doing anything with the argument passed, you can replace lambda expression with method reference.
getitem_rlist=lambda s,i: getitem_rlist(s[1:][0],i-1) if i > 0 else s[0]
maybe what you want .... Its hard to tell withpout knowing what those other methods do ...
>>> getitem_rlist=lambda s,i: getitem_rlist(s[1:][0],i-1) if i > 0 else s[0]
>>> s=(1,(2,(3,4)))
>>> getitem_rlist(s,2)
3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With