Сompare字典列表中的所有url相互关联



我有一个字典列表:

list = [
{'system': 'account-d84', 'version': '1.2.16', 'contour': {'test': {'urls': {'db_diasoft_datasource_jdbc-url': 'jdbc:sqlserver://diasoftGLtest.rccf.ru:49031;databaseName=DiasoftGLtest', 'ws_url': 'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'}}}},
{'system': 'account-d84', 'version': '1.2.12', 'contour': {'cards': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://diasoftGLCards.rccf.ru:49064;databaseName=diasoftglCARDS', 'ws_url': 'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'}}}},
{'system': 'account-d84', 'version': '1.2.12', 'contour': {'gp': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://diasoftGLGP.rccf.ru:49040;databaseName=diasoftglGP', 'ws_url': 'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'}}}},
{'system': 'account-d84', 'version': '1.2.16', 'contour': {'dev': {'urls': {'db_diasoft_datasource_jdbc-url': 'jdbc:sqlserver://diasoftGLtest.rccf.ru:49031;databaseName=DiasoftGLtest', 'ws_url': 'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'}}}},
{'system': 'account-d84', 'version': '1.2.18', 'contour': {'preprod': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://DiasoftGK-Hagl.rccf.ru:1433/DiasoftGL'}}}},
{'system': 'account-d84', 'version': '1.2.18', 'contour': {'preprodft': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://SRVDB253.rccf.ru:1433/DiasoftGLft'}}}},
{'system': 'account-d84', 'version': '1.2.18', 'contour': {'prod': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://DiasoftGK-Hagl.rccf.ru:1433/DiasoftGL'}}}}
]

我如何在Python中为键key=db_diasoft_datasource_jdbc-urlkey=db_diasoft_datasource_url找到不同轮廓的相同url值?

例如:url'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'等于test, cards, gp and dev'jdbc:jtds:sqlserver://DiasoftGK-Hagl.rccf.ru:1433/DiasoftGL'=preprod and prod

我需要输出system,version,contoururls,其中有相同的url。

我不知道这是否有帮助因为我不太明白你的问题的解释但这个算法给你所有的唯一url key=db_diasoft_datasource_jdbc-url或key=db_diasoft_datasource_url它们的轮廓像这样:

{
"jdbc:sqlserver://diasoftGLtest.rccf.ru:49031;databaseName=DiasoftGLtest": ["test", "dev"],
"jdbc:jtds:sqlserver://diasoftGLCards.rccf.ru:49064;databaseName=diasoftglCARDS": ["cards"],
"jdbc:jtds:sqlserver://diasoftGLGP.rccf.ru:49040;databaseName=diasoftglGP": ["gp"],
"jdbc:jtds:sqlserver://CLSDB3014.rccf.ru:1433/DiasoftGLnt": ["preprod"],
"jdbc:jtds:sqlserver://SRVDB253.rccf.ru:1433/DiasoftGLft": ["preprodft"],
"jdbc:jtds:sqlserver://DiasoftGK-Hagl.rccf.ru:1433/DiasoftGL": ["prod"]
}

代码:

list = [
{'system': 'account-d84', 'version': '1.2.16', 'contour': {'test': {'urls': {'db_diasoft_datasource_jdbc-url': 'jdbc:sqlserver://diasoftGLtest.rccf.ru:49031;databaseName=DiasoftGLtest', 'ws_url': 'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'}}}},
{'system': 'account-d84', 'version': '1.2.12', 'contour': {'cards': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://diasoftGLCards.rccf.ru:49064;databaseName=diasoftglCARDS', 'ws_url': 'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'}}}},
{'system': 'account-d84', 'version': '1.2.12', 'contour': {'gp': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://diasoftGLGP.rccf.ru:49040;databaseName=diasoftglGP', 'ws_url': 'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'}}}},
{'system': 'account-d84', 'version': '1.2.16', 'contour': {'dev': {'urls': {'db_diasoft_datasource_jdbc-url': 'jdbc:sqlserver://diasoftGLtest.rccf.ru:49031;databaseName=DiasoftGLtest', 'ws_url': 'http://fssp-dev-dev-fa-glws.apps.test.k8s.rccf.ru/glws/glws'}}}},
{'system': 'account-d84', 'version': '1.2.18', 'contour': {'preprod': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://CLSDB3014.rccf.ru:1433/DiasoftGLnt'}}}},
{'system': 'account-d84', 'version': '1.2.18', 'contour': {'preprodft': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://SRVDB253.rccf.ru:1433/DiasoftGLft'}}}},
{'system': 'account-d84', 'version': '1.2.18', 'contour': {'prod': {'urls': {'db_diasoft_datasource_url': 'jdbc:jtds:sqlserver://DiasoftGK-Hagl.rccf.ru:1433/DiasoftGL'}}}}
]
h = {}
for i in list:
for j in i["contour"]:
for k in i["contour"][j]["urls"]:
if (k == "db_diasoft_datasource_jdbc-url" or k == "db_diasoft_datasource_url"):
if i["contour"][j]["urls"][k] in h:
h[i["contour"][j]["urls"][k]].append(j)
else:
h[i["contour"][j]["urls"][k]] = [(j)]

相关内容

  • 没有找到相关文章

最新更新