Counting the Number of keywords in a dictionary in python

前端 未结 5 1563
离开以前
离开以前 2020-12-04 08:11

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. I

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 08:40

    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()))
    

提交回复
热议问题