Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python If I have a dictonary with keys that contain mutliple values and a single value how to filter out only keys that contain multiple values

word_freq = {'is': [1, 3, 4, 8, 10],'no' :[1], 'yes':[1,2]}

I want to only get ‘is’ and ‘yes’ using the fact that they contain more than one value.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can try this:

for i in word_freq:
    if len(word_freq[i]) > 1:
        print(word_freq[i])

It loops through the dictionary in word_freq and if the items/values in the word_freq are more than 1 then it prints them out.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading