要查找
seq与匹配的序列中的第一个元素
predicate:
next(x for x in seq if predicate(x))
或(
itertools.ifilter在Python 2上):
next(filter(predicate, seq))
StopIteration如果没有,它将引发。
None如果没有这样的元素,则返回:
next((x for x in seq if predicate(x)), None)
要么:
next(filter(predicate, seq), None)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)