组合数据类型练习,英文词频统计实例上

1、字典实例:建立学生学号成绩字典,做增删改查遍历操作。

 建立:

d={'0001':'99','0003':'89','0004':'98','0005':'100','0006':'78'}

增:
d['0002']='79'

删:
d.pop('0001')

改:
d['0004']=100

查:
print(d['0002'])

遍历操作:
for i in d:
    print(d)

2、列表,元组,字典,集合的遍历。

l=list('12438849374837')
for i in l:
    print(l)

t=tuple('nhaildhabvka')
for i in t:
    print(t)

d={'0001':'99','0003':'89','0004':'98','0005':'100','0006':'78'}
for i in d:
    print(d)

s=set(l)
for i in s:
    print(s)


总结列表,元组,字典,集合的联系与区别。

列表:是一组有序序列,能进行查询,增加,删除,修改。是用中括号【】括起来的。

元组:是一组有序序列,能进行查询。是用小括号()括起来的。

字典:字典不是有序序列,是由一组组键值对组成。能进行增删改查等操作。是用大括号{}括起来的。

集合:集合也不是有序序列,能进行查询等操作。是用大括号{}括起来的。

3、英文词频统计实例

     (1)待分析字符串

 bin='''Put your make up on

Get your nails done

Curl your hair

Run the extra mile

Keep it slim

so they like you, do they like you?

Get your sexy on

Don't be shy, girl

Take it off

This is what you want, to belong, so they like you

Do you like you?

You don't have to try so hard

You don't have to, give it all away

You just have to get up, get up, get up, get up

You don't have to change a single thing

You don't have to try, try, try, try

You don't have to try, try, try, try

You don't have to try, try, try, try

You don't have to try

Yooou don't have to try

Oooh Oooh

Get your shopping on, at the mall, max your credit card

You don't have to choose, buy it all, so they like you

Do they like you?

Wait a second,Why, should you care, what they think of you

When you're all alone, by yourself, do you like you?

Do you like you?You don't have to try so hard

You don't have to, give it all away

You just have to get up, get up, get up, get up

You don't have to change a single thing

You don't have to try so hard

You don't have to bend until you break

You just have to get up, get up, get up, get up

You don't have to change a single thing

You don't have to try, try, try, try

You don't have to try, try, try, try

You don't have to try

You don't have to try

You don't have to try, try, try, try

You don't have to try, try, try, try

You don't have to try, try, try, try

You don't have to tryYooou don't have to try

NooooOooh

You don't have to try so hard

You don't have to, give it all away

You just have to get up, get up, get up, get up

You don't have to change a single thing

You don't have to try, try, try, tryYou don't have to try, try, try, try

You don't have to try, try, try, try

You don't have to try

Take your make up off

Put your head down

Take a breath

Look into the mirror, at yourself.

Don't you like you?

Cause I like you!'''

     (2)分解提取单词

             大小写 txt.lower()

bin=bin.lower()

             分隔符'.,:;?!-_’

for i in ',.?!\n':
    bin=bin.replace(i,' ')

             单词列表

bin=bin.split(" ")

     (3)单词计数字典

words=set(bin)
d={}
d['star']=bin.count('star')
for a in words:
    d[a]=bin.count(a)
for a in d:
    print("{0:<11}{1}".format(a,d[a]))

转载于:https://www.cnblogs.com/018linbin/p/7573294.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540583.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

茱莉亚分形_茱莉亚的NaN Constant

茱莉亚分形Julia| NaN / Nan64常数 (Julia | NaN/Nan64 Constant) Nan / Nan64 is a constant of the Float64 type in Julia programming language, it represents "not-a-number" value. Nan / Nan64是Julia编程语言中Float64类型的常量&#xff0c;它表示“非数字…

[转载] Python3 数组

参考链接&#xff1a; Python中的Array | 数组1(简介和功能) 一、list和array的区别 Python的数组通过Numpy包的array实现。 Python里二者最大的区别是&#xff0c;list可以存储不同类型的数据&#xff0c;而array只能存储相同类型的数据。 import numpy #直接定义 a […

201671010128 2017-09-24《Java程序设计》之继承

1.继承的概念及理解&#xff1a; 继承是java面向对象编程技术的一块基石&#xff0c;因为它允许创建分等级层次的类。继承就是子类继承父类的特征和行为&#xff0c;使得子类对象&#xff08;实例&#xff09;具有父类的实例域和方法&#xff0c;或子类从父类继承方法&#xff…

紫外线的形式是什么?

紫外线&#xff1a;紫外线 (UV: Ultraviolet) UV is an abbreviation of Ultraviolet. In RO water purifiers, the bacteria or germs which are present in the water cannot get killed by reverse osmosis process but this process can banish the dissolved solids and i…

[js高手之路] html5 canvas系列教程 - 掌握画直线图形的常用API

我们接着上文[js高手之路] html5 canvas系列教程 - 认识canvas以及基本使用方法继续. 一、直线的绘制 cxt.moveTo( x1, y1 )&#xff1a; 将画笔移动到x1, y1这个点 cxt.lineTo( x2, y2 )&#xff1a;将画笔从起点开始画直线&#xff0c;一直画到终点坐标( x2, y2 ) cxt.stroke…

金矿问题

Description: 描述&#xff1a; This is a standard interview problem featured in interview coding rounds of Amazon, Flipkart. 这是亚马逊Flipkart的采访编码回合中的标准采访问题。 Problem statement: 问题陈述&#xff1a; Given a gold mine of n*m dimensions, e…

[转载] python中的数组类型及特点

参考链接&#xff1a; Python中的Array | 数组2(简介和功能) 名称 表示方法示例 是否有序 函数方法&#xff08;增删等&#xff09; 特点 List 类型表示&#xff1a;L L [Adam, 95.5, Lisa, 85] 有序 增加&#xff1a;&#xff08;1&#xff09;L.append(Paul),增加…

puppet

Puppet前期环境&#xff08;网络、解析、yum源、NTP&#xff09;在上一章节已经准备就绪&#xff0c;接下来我们就开始安装Puppet了&#xff0c;安装Puppet其实很简单&#xff0c;官方已经提供了yum源&#xff0c;只需要自己将所需要的安装包下载下来然后做成本地yum源即可使用…

[转载] 【数学问题】利用python求解表达式

参考链接&#xff1a; Python 变量 &#xff5c;表达式 &#xff5c;条件和函数 有时候我们会遇到一些很复杂的表达式&#xff0c;或者想要求解某个表达式&#xff0c;但是手动计算的话不但耗时还费精力&#xff0c;我们能不能利用计算机来帮助我们进行计算呢&#xff1f; 1…

cesium广告牌_公路广告牌

cesium广告牌Description: 描述&#xff1a; This is a standard dynamic programing problem of finding maximum profits with some constraints. This can be featured in any interview coding rounds. 这是在某些约束条件下找到最大利润的标准动态编程问题。 这可以在任何…

你和大牛差了啥

mmp。无时无刻不在想和大牛差在哪里了。别人为什么可以那么牛逼而你tmd那么菜&#xff01;整个人顿时都颓废了。啥事儿不想干。后来想了想感情就是他比较黑吧。

[转载] python数组的使用

参考链接&#xff1a; Python中整数的最大可能值是多少&#xff1f; 原文地址为&#xff1a; python数组的使用 python数组的使用 python数组的使用 2010-07-28 17:17 1、Python的数组分三种类型&#xff1a; (1) list 普通的链表&#xff0c;初始化后可以通过特定方法…

scala中循环守卫_Scala中的循环

scala中循环守卫Scala中的循环 (Loops in Scala) In programming, many times a condition comes when we need to execute the same statement or block of code more than one time. It could be difficult to write the same code multiple times, so programing language d…

50个必备基础命令

1.tar创建一个新的tar文件$ tar cvf archive_name.tar dirname/解压tar文件$ tar xvf archive_name.tar查看tar文件$ tar tvf archive_name.tar2. grep在文件中查找字符串(不区分大小写)$ grep -i "the" demo_file输出成功匹配的行&#xff0c;以及该行之后的三行$ g…

NM的完整形式是什么?

NM&#xff1a;无消息 (NM: No Message) NM is an abbreviation of "No Message". NM是“无消息”的缩写。 It is an expression, which is commonly used in the Gmail platform. It is also written as N/M or n/m or *n/m*. It is written in the subject of the…

[转载] python中全局变量和局部变量解析

参考链接&#xff1a; Python中的全局变量和局部变量 python函数中可以访问全局变量但是不能给全局变量赋值&#xff0c;除非进行显式声明global a 比如定义了全局变量 a 在函数my_fun()中可以直接访问a的值&#xff0c;而不需要global全局变量申明。下图为上面代码运行输出 …

【iCore4 双核心板_FPGA】例程十六:基于双口RAM的ARM+FPGA数据存取实验

实验现象&#xff1a; 核心代码&#xff1a; int main(void) {/* USER CODE BEGIN 1 */int i;int address,data;char error_flag 0;char receive_data[50];char buffer[8];char *p;/* USER CODE END 1 *//* MCU Configuration-----------------------------------------------…

[转载] Python中TFTP的理解

参考链接&#xff1a; Python中的打包pack和拆包unpack参数 Num01–>TFTP协议介绍 TFTP&#xff08;Trivial File Transfer Protocol,简单文件传输协议&#xff09; 是TCP/IP协议族中的一个用来在客户端与服务器之间进行简单文件传输的协议 特点&#xff1a; 1,简单 2…

gn fast-gn_GN的完整形式是什么?

gn fast-gnGN&#xff1a;晚安 (GN: Good Night) GN is an abbreviation of "Good Night". GN是“ Good Night”的缩写 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Yahoo Messenge…

从零开始编写自己的C#框架(27)——什么是开发框架

前言 做为一个程序员&#xff0c;在开发的过程中会发现&#xff0c;有框架同无框架&#xff0c;做起事来是完全不同的概念&#xff0c;关系到开发的效率、程序的健壮、性能、团队协作、后续功能维护、扩展......等方方面面的事情。很多朋友在学习搭建自己的框架&#xff0c;很多…