iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐕
Array.find in Python
A function that retrieves the first element in an array that satisfies a specific condition.
Returns None if no such element is found.
def find(func, arr):
rs = list(filter(func, arr))
if len(rs) == 0: return None
return rs[0]
find(lambda v: v > 100, [1, 2, 101, 200])
# 101
print(find(lambda v: v > 100, [1, 2, 11, 20]))
# None
Discussion