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? 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())) The number of distinct words (i.e. count of entries in the dictionary) can be found using the len() function. > a = {'foo':42, 'bar':69} > len(a) 2 To get