[英]Need to convert to lambda function
i try to write this function to lambda function,I tried a lot of options and I could not success: 我尝试将此函数编写为lambda函数,尝试了很多选项,但无法成功:
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 例如:
s=(1,(2,(3,4)))
然后getitem_rlist(a,2))# -> 3
函数需要返回递归列表s的索引i处的元素
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.