import numpy as np
array = np.asarray(a)
def searchForWord(array, word):
#base case
if (array.size == 0) return false
#recursive case
if word in array[0] return true
array = np.delete(array, 0)
searchForWord(array, word)
def find(text, data):
# loop over all items (tuples or strings)
for item in data:
# if it's a tuple, recurse
if isinstance(item, tuple):
if find(text, item):
return True
# if it's a string and a match return true
if item==text:
return True
return False
以下是一个例子:
您可能会遇到问题,因为numpy数组将是元组数组。只要让我知道它是否有效
您可以递归地执行此操作:
输出:
相关问题 更多 >
编程相关推荐