0

是否有任何选项可以为类似的东西写一个衬里:

def my_func(some_iter):
    return next('yes' for x in some_iter if x%2 == 0) or None

some_list1 = [1, 2, 3, 4]
some_list2 = [1, 7, 3, 5]
print(my_func(some_list1)) # should return 'yes'
print(my_func(some_list2)) # should return none

所以它应该迭代事物,直到找到匹配的选项,如果没有匹配的选项,那么它应该返回 None

4

0 回答 0