简体   繁体   English

将Python列表中的键值与多个词典进行比较

[英]Compare values of keys in Python list with multiple dictionaries

I have a list made up of dictionaries. 我有一个由字典组成的列表。 What I need to do is compare the value of key "a" (172.60) in one dictionary, and if it is 30% greater than the key "b" (168.80) value in the same dictionary then print the value of "value". 我需要做的是比较一个字典中键“a”(172.60)的值,如果它比同一个字典中的键“b”(168.80)值大30%那么打印“值”的值。 And iterate over all of the dictionaries in the entire list.I have tried many different 'for' and 'if' constructs but the solution escapes me. 并遍历整个列表中的所有字典。我尝试了许多不同的'for'和'if'结构,但解决方案让我感到厌烦。 I am using python v2.6.6. 我使用的是python v2.6.6。

List1= [{"p":0,"c":0,"b":168.80,"a":172.60,"oi":0,"vol":0,"value":355.00},
        {"p":0,"c":0,"b":163.80,"a":167.60,"oi":0,"vol":0,"value":360.00}]

One way to do it: 一种方法:

for dd in List1:
    if dd["a"] > 1.3 * dd["b"]:
        print dd["value"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM