如何从python字典中的元组访问密钥?

时间:2019-07-10 03:49:37

标签: python

我有这样的字典;

  csvDict[key] = {'delivery': delivery, 'tanksystemid': tanksystemid}

我正在尝试进行条件检查;

tanksystemid=100

for dic in csvDict.values():
                if tanksystemid == dic['tanksystemid']:
                    key of csvDict?

如何获取csvDict的密钥?

1 个答案:

答案 0 :(得分:0)

您只需要使用csvDict.items()而不是csvDict.values()。像(python3)一样:

tanksystemid=100
for key, dic in csvDict.items():
                if tanksystemid == dic['tanksystemid']:
                    # key of csvDict?
                    print(f'key: {key}')