Counting the Number of keywords in a dictionary in python
问题 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? 回答1: len(yourdict.keys()) or just len(yourdict) If you like to count unique words in the file, you could just use set and do like len(set(open(yourdictfile).read().split())) 回答2: The number of distinct words (i.e. count