此脚本的目标是将当前版本的客户端软件与供应商提供的当前软件版本进行比较。在这个阶段,我只想打印出可用的内容。
我有两个字典设置:
versions = {
'v80':[80.24,80.16,80.15,80.7],
'v81':[81.12,81.7,81.4,81.11],
'v82':[82.7,82.5,82.9,82.6],
'v83':[83.0,83.1,83.1,83.0]
}
client = {
'client_1':[80.1,80.1,80.1,80.1],
'client_2':[81.1,80.1,80.1,80.1],
'client_3':[82.1,80.1,80.1,80.1],
'client_4':[81.1," ",80.1,80.1],
'client_5':[80.1," "," "," "]
}
版本=可用的内容/客户端=客户端正在运行的版本
有4个关键值代表4个不同的应用程序及其所依据的版本。
我已尝试了一些方法,但我已经用它撞墙了。
我想将client_ [n]中的键值与相应的版本进行比较(不确定如何将client_3与v83,client1与v80等链接)。比较将只是:
if client['client_1'][0] < versions['v80'][0]
print(client.client_1[0],"-->",versions.v80[0])
先谢谢!
答案 0 :(得分:0)
您可以引入充当接口的第三个字典
panel.lines
现在只需使用以下内容进行比较:
label.xyplot(...)
答案 1 :(得分:0)
您可以使用以下for循环:
>>> for i in range(len(versions)):
... for j in range(len(versions['v8'+str(i)])):
... try:
... if client['client_' + str(i+1)][j] < versions['v8' + str(i)][j]:
... print ("client_" + str(i+1), "Program_" + str(j+1), client["client_" + str(i+1)][j],"-->",versions["v8"+str(i)][j])
... except TypeError:
... print ("client_" + str(i+1), "Program_" + str(j+1), "Missing")
... continue
...
client_1 Program_1 80.1 --> 80.24
client_1 Program_2 80.1 --> 80.16
client_1 Program_3 80.1 --> 80.15
client_1 Program_4 80.1 --> 80.7
client_2 Program_1 81.1 --> 81.12
client_2 Program_2 80.1 --> 81.7
client_2 Program_3 80.1 --> 81.4
client_2 Program_4 80.1 --> 81.11
client_3 Program_1 82.1 --> 82.7
client_3 Program_2 80.1 --> 82.5
client_3 Program_3 80.1 --> 82.9
client_3 Program_4 80.1 --> 82.6
client_4 Program_1 81.1 --> 83.0
client_4 Program_2 Missing
client_4 Program_3 80.1 --> 83.1
client_4 Program_4 80.1 --> 83.0
但是,这取决于您提供的信息是否一致,versions
和clients
的数量是否相同,具有相同的长度列表。
如果你更清楚一点,我可以尝试更强大的解决方案。
答案 2 :(得分:-1)
您可以尝试:
if client['client_1'][0] < versions['v80'][0]:
print(client["client_1"][0] ,"-->",versions["v80"][0])
为所有客户端和版本执行此操作:
versions = {
'v80':[80.24,80.16,80.15,80.7],
'v81':[81.12,81.7,81.4,81.11],
'v82':[82.7,82.5,82.9,82.6],
'v83':[83.0,83.1,83.1,83.0]
}
client = {
'client_1':[80.1,80.1,80.1,80.1],
'client_2':[81.1,80.1,80.1,80.1],
'client_3':[82.1,80.1,80.1,80.1],
'client_4':[81.1," ",80.1,80.1],
'client_5':[80.1," "," "," "]
}
for cli, num_cl in client.items():
for ver, num in versions.items():
if int(num[0]) == int(num_cl[0]):
print(cli, num_cl, ver, num)
输出:
client_4 [81.1, ' ', 80.1, 80.1] v81 [81.12, 81.7, 81.4, 81.11]
client_5 [80.1, ' ', ' ', ' '] v80 [80.24, 80.16, 80.15, 80.7]
client_2 [81.1, 80.1, 80.1, 80.1] v81 [81.12, 81.7, 81.4, 81.11]
client_3 [82.1, 80.1, 80.1, 80.1] v82 [82.7, 82.5, 82.9, 82.6]
client_1 [80.1, 80.1, 80.1, 80.1] v80 [80.24, 80.16, 80.15, 80.7]