>>> d = next(item for item in l if item['user'] == 'unknown user')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
如果指定了default,则会发生以下情况:
>>> next((item for item in l if item['user'] == 'unknown user'), 'Nothing found')
'Nothing found'
您还可以使用^{} :
印刷品:
^{pr2}$请注意,如果在调用
next()
时未指定default
(第二个参数),则会引发StopIteration
异常:如果指定了
default
,则会发生以下情况:相关问题 更多 >
编程相关推荐