Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (45.3k points)

I have a dictionary like this;

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

I'm 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?

1 Answer

0 votes
by (16.8k points)

Don't use csvDict.values(), just use csvDict.items().

Like here, in Python 3:

tanksystemid=100

for key, dic in csvDict.items():

                if tanksystemid == dic['tanksystemid']:

                    # key of csvDict?

                    print(f'key: {key}')

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...