📌  相关文章
📜  在列表中查找与条件匹配的元素 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:14.549000             🧑  作者: Mango

代码示例1
#In Python 2.6 or newer:

#If you want StopIteration to be raised if no matching element is found:
next(x for x in the_iterable if x > 3)
#If you want default_value (e.g. None) to be returned instead:
next((x for x in the_iterable if x > 3), default_value)