javascript - javascript 的 every() 在 python 中相当于什么?

标签 javascript python

我有这个代码,我正在从 js 翻译成 python,我有这个:

if( this.risultato.every((v, i) => v === this.atteso[i]) ){}

Python 中 every(); 的等价物是什么?函数,如果它不是内置的,我如何创建类似的函数?对于箭头功能部分,我找到了这个解决方案:

lambda v, i: v == self.atteso[i]

最佳答案

Python 中的等价物是 all 函数:

mylist = [True, True, True]
x = all(mylist)

或者:

def all(iterable):
    for element in iterable:
        if not element:
            return False
    return True

关于javascript - javascript 的 every() 在 python 中相当于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70101757/

相关文章:

javascript - 图像的窗口位置 href

python - Twilio 模块通过 Python 发送电子邮件内容

python - 在 Python 中,如何在 format() 中传递变量?

javascript - 缩小 angularjs 应用程序时出现错误 : Unexpected token punc «)», 预期的 punc «,»

Javascript "switch statement"使用 getElementstByName.value 从 "input type text"获取测试值

javascript - Vue 组件和 AJAX 加载 HTML 内容

Python 调用记录。获取基类名称

javascript - 如何动态创建具有 "onclick"事件属性的提交按钮?

python - 字典: how to compare values and merge if values are the same?

python - 在 Ubuntu 中查找包的属性