为了让我接管黑客帝国,我首先需要把约翰·威克从里面除掉。他很擅长隐藏(很明显),所以他把自己分成了一个列表和列表中的列表。例如:
environment = ["a", [**"j"**, "e", **"o"**], [**"h"**, **"n"**, "s",
**"w"**, "o"], [**"i", "c", "k"**]]
target = "johnwick"
只有双递归才能将John Wick从矩阵的列表中删除。他不属于这里。到目前为止,我得出的结论是:
def no_wick(environment):
target = "johnwick"
clean_matrix = []
if not environment:
return clean_matrix
elif isinstance(environment[0], list):
???????
elif environment[0] not in target:
return clean_matrix.append(environment[0]) + no_wick(environment[1:])
else:
return no_wick(environment[1:])
你能帮我把约翰·威克从黑客帝国除掉吗,而我要照顾托马斯·A·安德森?你知道吗
递归,带有一点可变参数的黑魔法:
提供:
如果我理解正确,这个例子可以帮助您:
如果我对这一点的理解是正确的,那么现有的三个答案并不能按规定解决问题。它们不使用双递归,而是使用
for
循环来替换其中一个递归。我猜你在找什么:输出
相关问题 更多 >
编程相关推荐