0

I have dictionary like this;

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

Im trying to do a condition check like;

tanksystemid=100

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

How can i get the key of the csvDict?

Ratha
  • 9,434
  • 17
  • 85
  • 163
  • 2
    Possible duplicate of [Iterating over dictionaries using 'for' loops](https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops) – Ignatius Jul 10 '19 at 03:52
  • 2
    If you need the key, use `for key, value in csvDict.items():` instead. – Henry Yik Jul 10 '19 at 03:52

1 Answers1

0

You need to just use csvDict.items() instead of csvDict.values(). Like (python3) :

tanksystemid=100
for key, dic in csvDict.items():
                if tanksystemid == dic['tanksystemid']:
                    # key of csvDict?
                    print(f'key: {key}')
Perplexabot
  • 1,852
  • 3
  • 19
  • 22