0 votes
1 view
in Python by (8.4k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...