# 使用Python进行词频统计

mytext = """Background
Industrial Light & Magic (ILM) was started in by filmmaker George Lucas, in order to create the special effects for the original Star Wars film. Since then, ILM has grown into a visual effects powerhouse that has contributed not just to the entire Star Wars series, but also to films as diverse as Forrest Gump, Jurassic Park, Who Framed Roger Rabbit, Raiders of the Lost Ark, and Terminator . ILM has won numerous Academy Awards for Best Visual Effects, not to mention a string of Clio awards for its work on television advertisements. While much of ILM's early work was done with miniature models and motion controlled cameras, ILM has long been on the bleeding edge of computer generated visual effects. Its computer graphics division dates back to 1979, and its first CG production was the 1982 Genesis sequence from Star Trek II: The Wrath of Khan. In the early days, ILM was involved with the creation of custom computer graphics hardware and software for scanning, modeling, rendering, and compositing (the process of joining rendered and scanned images together). Some of these systems made significant advances in areas such as morphing and simulating muscles and hair. Naturally, as time went by many of the early innovations at ILM made it into the commercial realm, but the company's position on the cutting edge of visual effects technology continues to rely on an ever-changing combination of custom in-house technologies and commercial products. Today, ILM runs a batch processing environment capable of modeling, rendering and compositing tens of thousands of motion picture frames per day. Thousands of machines running Linux, IRIX, Compaq Tru64, OS X, Solaris, and Windows join together to provide a production pipeline that is used by approximately eight hundred users daily, many of whom write or modify code that controls every step of the production process. In this context, hundreds of commercial and in-house software components are combined to create and process each frame of computer-generated or enhanced film. Making all this work, and keeping it working, requires a certain degree of technical wizardry, as well as a tool set that is up to the task of integrating diverse and frequently changing systems. Enter Python
Back in , in the Dalmation days, ILM was exclusively an SGI IRIX shop, and the production pipeline was controlled by Unix shell scripting.
At that time, ILM was producing - shots per show, typically only a small part of each feature length film to which they were contributing.""" def wordcount(str):
strl_list = str.replace('\n', '').lower().split(" ") count_dict = {}
for str in strl_list:
if str in count_dict.keys():
count_dict[str] = count_dict[str] +
else:
count_dict[str] =
count_list = sorted(count_dict.items(), key=lambda x: x[], reverse=True)
return count_list print(wordcount(mytext))

示例:

E:\Python37\python.exe E:/PythonTest/Test/Test002.py
[('of', ), ('the', ), ('and', ), ('to', ), ('ilm', ), ('was', ), ('a', ), ('in', ), ('as', ), ('that', ), ('by', ), ('for', ), ('has', ), ('visual', ), ('on', ), ('production', ), ('effects', ), ('star', ), ('its', ), ('early', ), ('computer', ), ('commercial', ), ('create', ), ('wars', ), ('into', ), ('not', ), ('but', ), ('diverse', ), ('awards', ), ('work', ), ('with', ), ('motion', ), ('controlled', ), ('edge', ), ('graphics', ), ('days,', ), ('custom', ), ('software', ), ('modeling,', ), ('compositing', ), ('process', ), ('made', ), ('many', ), ('at', ), ('it', ), ('an', ), ('in-house', ), ('thousands', ), ('per', ), ('pipeline', ), ('is', ), ('or', ), ('this', ), ('each', ), ('background', ), ('industrial', ), ('light', ), ('&', ), ('magic', ), ('(ilm)', ), ('started', ), ('', ), ('filmmaker', ), ('george', ), ('lucas,', ), ('order', ), ('special', ), ('original', ), ('film.', ), ('since', ), ('then,', ), ('grown', ), ('powerhouse', ), ('contributed', ), ('just', ), ('entire', ), ('series,', ), ('also', ), ('films', ), ('forrest', ), ('gump,', ), ('jurassic', ), ('park,', ), ('who', ), ('framed', ), ('roger', ), ('rabbit,', ), ('raiders', ), ('lost', ), ('ark,', ), ('terminator', ), ('2.', ), ('won', ), ('numerous', ), ('academy', ), ('best', ), ('effects,', ), ('mention', ), ('string', ), ('clio', ), ('television', ), ('advertisements.while', ), ('much', ), ("ilm's", ), ('done', ), ('miniature', ), ('models', ), ('cameras,', ), ('long', ), ('been', ), ('bleeding', ), ('generated', ), ('effects.', ), ('division', ), ('dates', ), ('back', ), ('1979,', ), ('first', ), ('cg', ), ('', ), ('genesis', ), ('sequence', ), ('from', ), ('trek', ), ('ii:', ), ('wrath', ), ('khan.in', ), ('involved', ), ('creation', ), ('hardware', ), ('scanning,', ), ('rendering,', ), ('(the', ), ('joining', ), ('rendered', ), ('scanned', ), ('images', ), ('together).', ), ('some', ), ('these', ), ('systems', ), ('significant', ), ('advances', ), ('areas', ), ('such', ), ('morphing', ), ('simulating', ), ('muscles', ), ('hair.naturally,', ), ('time', ), ('went', ), ('innovations', ), ('realm,', ), ("company's", ), ('position', ), ('cutting', ), ('technology', ), ('continues', ), ('rely', ), ('ever-changing', ), ('combination', ), ('technologies', ), ('products.today,', ), ('runs', ), ('batch', ), ('processing', ), ('environment', ), ('capable', ), ('rendering', ), ('tens', ), ('picture', ), ('frames', ), ('day.', ), ('machines', ), ('running', ), ('linux,', ), ('irix,', ), ('compaq', ), ('tru64,', ), ('os', ), ('x,', ), ('solaris,', ), ('windows', ), ('join', ), ('together', ), ('provide', ), ('used', ), ('approximately', ), ('eight', ), ('hundred', ), ('users', ), ('daily,', ), ('whom', ), ('write', ), ('modify', ), ('code', ), ('controls', ), ('every', ), ('step', ), ('process.', ), ('context,', ), ('hundreds', ), ('components', ), ('are', ), ('combined', ), ('frame', ), ('computer-generated', ), ('enhanced', ), ('film.making', ), ('all', ), ('work,', ), ('keeping', ), ('working,', ), ('requires', ), ('certain', ), ('degree', ), ('technical', ), ('wizardry,', ), ('well', ), ('tool', ), ('set', ), ('up', ), ('task', ), ('integrating', ), ('frequently', ), ('changing', ), ('systems.enter', ), ('pythonback', ), ('1996,', ), ('', ), ('dalmation', ), ('exclusively', ), ('sgi', ), ('irix', ), ('shop,', ), ('unix', ), ('shell', ), ('scripting.', ), ('time,', ), ('producing', ), ('15-30', ), ('shots', ), ('show,', ), ('typically', ), ('only', ), ('small', ), ('part', ), ('feature', ), ('length', ), ('film', ), ('which', ), ('they', ), ('were', ), ('contributing.', )] Process finished with exit code

Python3.7 练习题(二) 使用Python进行文本词频统计的更多相关文章

  1. 用Python实现一个词频统计(词云+图)

    第一步:首先需要安装工具python 第二步:在电脑cmd后台下载安装如下工具: (有一些是安装好python电脑自带有哦) 有一些会出现一种情况就是安装不了词云展示库 有下面解决方法,需看请复制链接 ...

  2. Python字典使用--词频统计的GUI实现

    字典是针对非序列集合而提供的一种数据类型,字典中的数据是无序排列的. 字典的操作 为字典增加一项 dict[key] = value students = {"Z004":&quo ...

  3. 利用python实现简单词频统计、构建词云

    1.利用jieba分词,排除停用词stopword之后,对文章中的词进行词频统计,并用matplotlib进行直方图展示 # coding: utf-8 import codecs import ma ...

  4. Python3.7 练习题(-) 如何使用Python生成200个优惠卷(激活码)

    # 如何使用Python生成200个优惠卷(激活码) import random import string # string.ascii_letters 26个大小写 # -9数字 # 获得激活码中 ...

  5. python3笔记(二)Python语言基础

    缩进 要求严格的代码缩进是python语法的一大特色,就像C语言家族(C.C++.Java等等)中的花括号一样重要,在大多数场合还非常有必要.在很多代码规范里面也都有要求代码书写按照一定的规则进行换行 ...

  6. Python3入门(二)——Python开发工具Pycharm安装与配置

    一.概述 与IDEA同一家——Jetbrains出品的IDE,强大之处不再赘述 二.安装 点击下载一个合适的版本 参考网友的激活方式激活:https://blog.csdn.net/u01404481 ...

  7. 零基础学python-3.7 还有一个程序 python读写文本

    今天我们引入另外一个程序,文件的读写 我们先把简单的程序代码贴上.然后通过我们多次的改进.希望最后可以变成一个简单的文本编辑器 以下是我们最简单的代码: 'crudfile--读写文件' def re ...

  8. python3笔记十二:python数据类型-Dictionary字典

    一:学习内容 字典概念 字典创建 字典访问 字典添加 字典删除 字典遍历 字典与列表比较 二:字典概念 1.使用键值对(key-value)存储,具有极快的查找速度 2.注意:字典是无序的 3.特性: ...

  9. jieba和文本词频统计

    ---恢复内容开始--- 一.结巴中文分词涉及到的算法包括: (1) 基于Trie树结构实现高效的词图扫描,生成句子中汉字所有可能成词情况所构成的有向无环图(DAG): (2) 采用了动态规划查找最大 ...

随机推荐

  1. 网络通信协议,TCP和UDP 的区别

    1.网络通信   互联网本质就是一系列的网络通信,互联网协议的功能是定义计算机如何介入internet,以及介入internet的计算机通信的标准.互联网协议按照功能不同分为osi7层或tcp/ip五 ...

  2. Oracle中 “ORA-14551: 无法在查询中执行 DML 操作” 如何解决

    在编写一个数据库函数时,方法实现需要查询后进行修改,出现ora-14551的错误 create or replace function fun_DxcBillSn(tabType integer,ta ...

  3. vs2015网站发布时,设置页面合并后程序集的文件版本

    如何将web网站的页面合并成一个新的程序集发布,并设定文件版本? 这个问题我也纠结了很久,问了很多大牛,也没有找到解决方案 曾开了一贴,https://bbs.csdn.net/topics/3910 ...

  4. 构建web应用之——文件上传

    我们通过使用multipart请求数据接收和处理二进制信息(如文件).DispatcherServlet并没有实现任何解析multipart请求数据的功能,它将该任务委托给了Spring中的multi ...

  5. bzoj2748

    题解: 简单dp 代码: #include<bits/stdc++.h> using namespace std; ; int n,x,m,a[N],f[N][N]; int main() ...

  6. Go 基础 坑

    1.字符串空为"" 2. 传递的数组是原数组的拷贝,所以是无法通过传递数组的方法去修改原地址的数据的.在GO语言中除了切片(slice).集合(map).通道(channel)和接 ...

  7. JS案例六_2:省市级联动

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. d3js可视化策略

    d3js是数据驱动图形的思路.基本可以这么理解,有什么样的图形,后面基本就有类似结构的数据.大概思路步骤如下: 一.适配数据格式 这一步主要是为第二部服务,第一步的结果作为第二部的入参. 比如,画层级 ...

  9. ubuntu安装后问题

    ubuntu安装后桌面显示不正常,出现闪屏,或者是缺图标的问题多数是ubuntu的3D加速显示问题 解决方法,vmware workstations 中的菜单栏:虚拟机->设置->显示器- ...

  10. 表单传值给@Controller

    <form action="springmvc/testModelAttributes" method="post"> <input type ...