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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.