Need to convert to lambda function

I am trying to write this function to a lambda function, I tried many options and I could not succeed:

def getitem_rlist(s, i): while i > 0: s, i = rest(s), i - 1 return first(s) 

I know for starters:

 getitem_rlist=lambda s,i:....? 

thanks! as an example, if: s=(1,(2,(3,4))) , then getitem_rlist(a,2))# -> 3 function should return the element to the index i of the recursive list s

+6
source share
1 answer
 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 say without knowing what these 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 
+2
source

Source: https://habr.com/ru/post/957785/


All Articles