L
L
lolchik2020-07-06 13:16:27
Python
lolchik, 2020-07-06 13:16:27

How to simplify getting a key by value?

There is a dictionary in which the values ​​are either True or False, only keys with True values ​​\u200b\u200bshould be displayed. I seem to have found it on stackoverflow, but somehow a lot is needed for such a simple operation, couldn't it be simpler?
https://ru.stackoverflow.com/questions/507330

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-07-06
@lo1chik

print([ k for (k, v) in d.items() if v ])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question