我遇到两个列表list1和list2的情况:
list1是应用程序的必备转速
and list2是系统中rpm的列表
list1 = ["binutils-2.23.52.0.1-12.el7.x86_64",
"compat-libcap1-1.10-3.el7.x86_64",
"compat-libstdc++-33-3.2.3-71.el7.i686",
"compat-libstdc++-33-3.2.3-71.el7.x86_64"]
list2 =['acl-2.2.51-12.el7.x86_64', 'adcli-0.8.1-3.el7.x86_64', 'audit-2.7.6-3.el7.x86_64', 'audit-libs-2.7.6-3.el7.i686', 'binutils-2.25.1-32.base.el7_4.2.x86_64','compat-libstdc++-33-3.2.3-72.el7.i686']
使用正则表达式创建了两个字典:
new_dict[match.group(1)] = {"name": s, "version": match.group ( 2 ), "build": match.group ( 3 ),"os": match.group ( 4 ), "arch": match.group ( 5 )}
old_dict[match1.group ( 1 )] = {"name": i, "version": match1.group ( 2 ), "build": match1.group ( 3 ),"os": match1.group ( 4 ), "arch": match1.group ( 5 )}
t_old = old_dict['libaio']['name']
print "t_old",t_old
t_new = new_dict['libaio']['name']
print "t_new",t_new
result =rpm.compare_packages(t_new, t_old)
print result
得到的输出:
t_old libaio-0.3.109-9.el7.x86_64
t_new libaio-0.3.109-13.el7.x86_64
1
t_new is newer
在这里我只能使用它的单个值,但是如何为old_dict的所有键执行此操作?