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 to count the number of keywords or is there another way I should look for distinct words?
+1
A:
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 all the distinct words (i.e. the keys), use the .keys()
method.
> list(a.keys())
['foo', 'bar']
KennyTM
2010-02-06 07:40:01
very nice. thanks a lot for the help!
Dan
2010-02-06 07:45:00
A:
I cannot understand your explanation. I think you might want to use a set
, not a list
. A set
is an unordered collection of unique elements.
Mike Graham
2010-02-06 07:40:24