I have a dictionary like this:
{'1956': 21,
'2188': 76,
'1307': 9,
'1305': 22,
'2196': 64,
'3161': 1,
'1025': 22,
'321': 60,
'1959': 1,
'1342': 7,
'3264': 2}
Where every keys are unique, I want to fetch those keys from the dictionary whose values are more than 60.
The output look like:
['2188','2196']
I can do it using a loop iteration using get('key') with a if condition, But that is a long process, what is the shortcut to do it more efficiently ?
[k for k, v in mydict.items() if v > 60]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With