计算python中字典中的关键字数 [英] Counting the Number of keywords in a dictionary in python

查看:637
本文介绍了计算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())

或者只是

len(yourdict)

如果您希望计算文件中的唯一单词,则可以使用 set 并喜欢

If you like to count unique words in the file, you could just use set and do like

len(set(open(yourdictfile).read().split()))

这篇关于计算python中字典中的关键字数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆