我正在检查,如果任何元素满足条件
if any( plus > minimum and minus > minimum for el in alist):
# do something
但在同一循环中有(添加):
if numpy.isnan(el.error):
plus = el.value
minus = el.value
else:
plus = el.value + el.error
minus = el.value - el.error
所以,我想要内部any()
函数,for循环和if else语句。
答案 0 :(得分:2)
如果我正确理解逻辑,您需要确保el.value
+/- el.error
大于minimum
,只要error
存在(否则只使用value
)。
您实际上不必检查双方,因为您可以在减去之前abs
error
def min_val(el):
if numpy.isnan(el.error):
return el.value
return el.value - numpy.abs(el.error)
。您可以定义辅助函数:
any
然后在if any(min_val(el) > minimum for el in alist):
来电中使用
any
您也可以将帮助程序编写为lambda,或者甚至将整个表达式粘贴到min_val = lambda el: el.value - (0 if numpy.isnan(el.error) else abs(el.error))
调用中,但它更难以阅读:
var a = (JSON.stringify({key1: "val1", key2 : "val2"}));
var exec = require('child_process').exec;
var execute = function(command, callback) {
exec(command, {maxBuffer: 1024 * 1000}, function(error, stdout, stderr) {callback(error, stdout);});
};
execute("curl -X POST -H 'Content-Type: application/json' -d '" + a +"' 'https://www.e-cotiz.com/api-payment-test/export/test.php'", function(error, stdout, stderr) {
// if(err) throw err;
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
答案 1 :(得分:1)
制作一个功能并在any
来电中使用
def checker(el, minimum):
plus = minus = 0 # make sure to initialize
if numpy.isnan(el.error):
plus = el.value
minus = el.value
else:
plus = el.value + el.error
minus = el.value - el.error
return plus > minimum and minus > minimum
然后使用any
:
if any(checker(el,minimum) for el in alist):
# do something!!
你也可以做一个令人作呕的一个班轮(与帕特里克的评论相似)。