nht*_*rnm 3 c++ python built-in
有没有更好的方法(使用内置函数)来重写下面的代码:
def all_of(iterable, predicate):
for elem in iterable:
if not predicate(elem):
return False
return True
Run Code Online (Sandbox Code Playgroud)
all 是内置的:
all(predicate(e) for e in iterable)
Run Code Online (Sandbox Code Playgroud)
我不认为定义这样的东西是值得的:
def all_of(iterable, predicate):
return all(predicate(e) for e in iterable)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
380 次 |
| 最近记录: |