我有一个这样组织的清单:

[('down', 0.0098000000000000309),
('up', 0.0015000000000000568),
('down', 0.008900000000000019),
('down', 0.023300000000000098),
('down', 0.011599999999999944),
('down', 0.0027000000000000357),
('up', 0.0023999999999999577),
('up', 0.0065000000000000613),
('down', 0.0057000000000000384),
('down', 0.018400000000000083),
('up', 0.009300000000000086),
('down', 0.0038000000000000256),
('down', 0.00050000000000005596),
('up', 0.0082000000000000961), .....


“反向比较”的最佳方法是什么? ,基本上,我想返回“是”(或其他任何值)。如果我们先后进行了2次“下降”,然后再进行一次“上升”,而第二个值则小于0.0095。

我希望他有道理..

最佳答案

干得好:

def frob(l):
    downcount = 0
    for ele in l:
        if downcount >= 2 and ele[0] == 'up' and ele[1] < 0.0095:
                return True
        downcount = (downcount + 1) if ele[0] == 'down' else 0
    return False

关于python - 倒数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6136716/

10-09 19:27