import nltk

 def freq_sorted(text,ranklimit):
fd=nltk.FreqDist(text)
cumulative = 0.0
for rank, (word,freq) in enumerate(sorted(fd.items(), key=lambda x: (-1*x[1], x[0]))[:ranklimit]):
cumulative += fd[word] * 100 / fd.N()
print "%3d %6.2f%% %s" % (rank+1, cumulative, word) def test_freq_sorted():
freq_sorted(nltk.corpus.brown.words(),15)

结果为:

  1   5.00% the
2 10.00% ,
3 14.00% .
4 17.00% of
5 19.00% and
6 21.00% to
7 22.00% a
8 23.00% in
9 23.00% that
10 23.00% is
11 23.00% was
12 23.00% for
13 23.00% ``
14 23.00% ''
15 23.00% The

Frequent Distribution sorted by frequency的更多相关文章

  1. [LeetCode] Top K Frequent Words 前K个高频词

    Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted b ...

  2. Top K Frequent Words

    Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted b ...

  3. [Swift]LeetCode692. 前K个高频单词 | Top K Frequent Words

    Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted b ...

  4. LeetCode - Top K Frequent Words

    Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted b ...

  5. [leetcode]692. Top K Frequent Words K个最常见单词

    Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted b ...

  6. #Leetcode# 692. Top K Frequent Words

    https://leetcode.com/problems/top-k-frequent-words/ Given a non-empty list of words, return the k mo ...

  7. 692. Top K Frequent Words

    Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted b ...

  8. [LC] 692. Top K Frequent Words

    Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted b ...

  9. 【LeetCode】692. Top K Frequent Words 解题报告(Python)

    [LeetCode]692. Top K Frequent Words 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/top ...

随机推荐

  1. Java学习笔记之多态

    1.父类型的引用可以指向子类型的对象: Parent p = new Child(); 2.当使用多态方式调用方法时,首先检查父类中是否有该方法,如果没有,则编译错误:如果有,再去调用子类的该同名方法 ...

  2. Timewarp 一种生成当中帧技术,异步时间扭曲(Asynchronous Timewarp)

    翻译: https://www.oculus.com/blog/asynchronous-timewarp/    异步时间扭曲(Asynchronous Timewarp 时间扭曲,即调整时长) 关 ...

  3. IO包中的其他类

    查看各对象API文档 打印流 PrintWriter PrintStream 序列流:对多个流进行排列合并 SequenceInputStream public static void main(St ...

  4. Windows下MySQL分步安装图解及问题总结

    MySQL是一个出色的开源数据库,在易用性和性能方面都有相当不错的表现.就作者发帖为止, MySQL官方发布的所有版本中(4.1/5.0/5.1/6.0),推荐使用稳定的MySQL5.0版本(商用). ...

  5. CST 公共生成树

    本实验只讨论CST(公共的生成树) 一.实验前先理解生成树决策的4 个步骤: 二.实验拓扑 1. 实验描述: 由于业务的要求,要有可靠的链路,要对链路实现冗余,但链路的冗余有可能给网络带来广播风暴,重 ...

  6. PopupWindow组件的使用问题

    //如果默认屏幕的话,父view就写自己 popupWindow.showAtLocation(inflate, Gravity.BOTTOM, 0, 0); PopupWindow 顾名思义为弹出式 ...

  7. (转)收集:Hibernate中常见问题 No row with the given identifier exists问题的原因及解决

    Hibernate中No row with the given identifier exists问题的原因及解决 产生此问题的原因: 有两张表,table1和table2.产生此问题的原因就是tab ...

  8. 用FusionChartsFree做饼状图、柱状图、折线图的实例

    1.先来看看要进行表现的页面:myChart.jsp <%@ page language="java" contentType="text/html; charse ...

  9. CentOS6.5 安装ntopng-1.2.0

    0.准备工作 安装libpcap:最好源码安装. yum install -y libpcap* 安装redis yum install -y redis* 1.安装 tar -zxvf ntopng ...

  10. Android平台中实现对XML的三种解析方式

    本文介绍在Android平台中实现对XML的三种解析方式. XML在各种开发中都广泛应用,Android也不例外.作为承载数据的一个重要角色,如何读写XML成为Android开发中一项重要的技能. 在 ...