I have a list of words in a dictionary with the value = the repetition of the keyword but I only want a list of distinct words so I wanted to count the number of keywords. Is there a way to count the number of keywords or is there another way I should look for distinct words?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
or just
If you like to count unique words in the file, you could just use
set
and do likeIf the question is about counting the number of keywords then would recommend something like
in the main function have something that loops through the data and pass the values to countoccurrences function
The code outputs
The number of distinct words (i.e. count of entries in the dictionary) can be found using the
len()
function.To get all the distinct words (i.e. the keys), use the
.keys()
method.