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

组合数据类型练习,英文词频统计实例1、列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。2、字典实例:建立学生学号成绩字典,做增删改查遍历操作

大家好,又见面了,我是你们的朋友全栈君。

1、列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。

m=list('123223121321312')
print('成绩:',m)
m.append('3')
print('增加:',m)
m.pop()
print('删除:',m)
m.insert(2,'2')
print('插入:',m)
m[2]='1'
print('修改:',m)
print('第一个3分index:',m.index('3'))
print('1分人数:',m.count('1'))
print('3分人数:',m.count('3'))

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

a={'周周':98,'张四':93,'李三':87,'李五':92,'周六':96}
print('学生成绩字典',a)
a['吴沟']=78
print('增加一个学生')
print(a)
a.pop('孙十一')
print('删除孙十一')
print(a)
a['吴沟']=87
print('修改吴沟的成绩')
print(a)
print('查找周周的成绩:',a.get('周周'))

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

m = list('123484123413216')
n = tuple('161231313535')
i = {'01':12,'03':546,'03':123456,'04':8524,'05':1546,'06':679}
j = {1, 2, 3, 4, 5}
print("列表遍历:",m)
print("元组遍历:",n)
print("字典遍历:",i)
print("集合遍历:",j)

列表:可读可修改,符号为[],可进行增删改查等操作。

元组:只读不可修改,符号为()。

字典:有键-值组,无序,符号为{}。

集合:可通过set函数实现集合,无序,可修改,符号为{}。

 

4、英文词频统计实例

待分析字符串分解提取单词

  1. 待分析字符串
  2. 分解提取单词
    1. 大小写 txt.lower()
    2. 分隔符’.,:;?!-_’
  3. 计数字典
    1. 排除语法型词汇,代词、冠词、连词

  4. 排序list.sort()
  5. 输出TOP(10)
news = '''For years, British explorer William Lindesay’s inquiries about a possible
extension of the Great Wall in Mongolia turned up nothing, but the researcher
recently had a breakthrough. Seeking insight from Professor Baasan Tudevin, a
lauded but hard-to-find expert on the region, Lindesay posted an advertisement
in a local newspaper. It was a long shot, but the two connected and the Mongolian
geographer said he knew of several such structures in the Gobi desert, the Telegraph reports.
Lindesay formed an expedition in August and with two Land Cruisers, 44 gallons of water,
12 gallons of extra gasoline and a lead from Google Earth, began poking around about 25 miles
from the sensitive Chinese-Mongolian border. Two days into the exploration, his team
discovered what is thought to be the first section of the Great Wall to exist outside
of China. Lost for nearly 1,000 years, the wall’s 62-mile-long arm is made mostly of shrubs
and dirt. Lindesay told the Telegraph much of the wall is about shin-level, but there is
also a stretch that reaches up to his shoulders.'''

exc ={'','the','of','a','but','two','about','in','is'}
news = news.lower()
for i in ',.':
    news = news.replace(i,' ')
words = news.split(' ')
dic = {}
keys = set(words)
for w in exc:
    keys.remove(w)
for i in keys:
    dic[i]=words.count(i)
wc = list(dic.items())
wc.sort(key=lambda x:x[1],reverse=True)
for i in range(10):
    print(wc[i])

5、文本操作

fo=open('/Users/Administrator/Desktop/test.txt','r')
news=fo.read()
fo.close()
exc={'','the','of','a','but','two','about','in','is'}
news =news.lower()
for i in ''',.?!"''':
    news=news.replace(i,' ')

print(news)
words=news.split(' ')
print(words)
d={}
keys = set(words)
for r in exc:
    keys.remove(r)
for i in keys:
    d[i]=words.count(i)
wc=list(d.items())
wc.sort(key=lambda x:x[1],reverse=True)
for i in range(10):
    print(wc[i])

 

 

 

(补交)大数据之NBA   2017-09-04

2017年NBA季后赛落幕后,网络上仍有大量关于NBA关键词的搜索。

这是近30天来,通过PC端和移动端搜索的趋势,可以看到有些日期的搜索指数是猛增的,因为NBA有大新闻爆出,比如8月23日,骑士与凯尔特人正式达成交易,小托马斯与欧文互换东家。

<span role="heading" aria-level="2">组合数据类型练习,英文词频统计实例

<span role="heading" aria-level="2">组合数据类型练习,英文词频统计实例

下面是8月份的搜索需求图谱。

<span role="heading" aria-level="2">组合数据类型练习,英文词频统计实例

下面是暑假期间的关于NBA搜索的地域分布,广东的搜索量全国第一。

<span role="heading" aria-level="2">组合数据类型练习,英文词频统计实例

下面是对NBA感兴趣的人群属性,女性只占极少数,而20至50岁的男性是NBA观众的主力军。

<span role="heading" aria-level="2">组合数据类型练习,英文词频统计实例

 

 

 

(补交)Python练习   2017-09-07

1、Hello World

print('hello world')

2、简单交换

name = input("输入姓名:")
print("{}同学,学好python,前途无量!".format(name))
print("{}大侠,学好python,前途无量!".format(name[0]))
print("{}哥哥,学好python,前途无量!".format(name[1:]))

3、输入两个数,计算两数之和(一行代码)

print('结果:%.0f'%float(float(input('输入第一个数字:'))+float(input('输入第二个数字:'))))

4、输入三角形三边长度,计算三角形面积(海伦公式)

复制代码
l1 = float(input('请输入第一条边的长度:'))
l2 = float(input('请输入第二条边的长度:'))
l3 = float(input('请输入第三条边的长度:'))
p = (l1+l2+l3) / 2
s = (p*(p-l1)*(p-l2)*(p-l3))**0.5
print('三角形的面积为:%.2f'%s)
复制代码

5、输入半径,计算圆的面积

radius = float(input("半径:"))
area = float(3.1415 * radius * radius)
print("面积:%.2f"%area)

6、画一组同切圆

复制代码
import turtle
turtle.circle(10)
turtle.circle(20)
turtle.circle(30)
turtle.circle(40)
turtle.circle(50)
复制代码

7、画一个五角星

复制代码
import turtle
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
复制代码

8、画一个全黄色五角星

复制代码
import turtle
turtle.color('yellow')
turtle.fillcolor('yellow')
turtle.begin_fill()
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.end_fill()
复制代码

9、画一组同心圆

复制代码
import turtle
turtle.penup()
turtle.goto(0,-200)
turtle.pendown()
turtle.circle(200)
turtle.penup()
turtle.goto(0,-150)
turtle.pendown()
turtle.circle(150)
turtle.penup()
turtle.goto(0,-100)
turtle.pendown()
turtle.circle(100)
复制代码

10、画国旗

复制代码
import turtle
turtle.color('yellow')
turtle.bgcolor('red')
turtle.fillcolor('yellow')

turtle.begin_fill()

turtle.up()
turtle.goto(-200,100)
turtle.down()

turtle.forward(150)
turtle.right(144)
turtle.forward(150)
turtle.right(144)
turtle.forward(150)
turtle.right(144)
turtle.forward(150)
turtle.right(144)
turtle.forward(150)
turtle.end_fill()

turtle.begin_fill()

turtle.up()
turtle.goto(-80,160)
turtle.down()

turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.end_fill()

turtle.begin_fill()

turtle.up()
turtle.goto(-22,68)
turtle.down()

turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.end_fill()

turtle.begin_fill()

turtle.up()
turtle.goto(-30,110)
turtle.down()

turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.end_fill()

turtle.begin_fill()

turtle.up()
turtle.goto(-45,-10)
turtle.down()

turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.end_fill()
复制代码

<span role="heading" aria-level="2">组合数据类型练习,英文词频统计实例

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/156170.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 一致性哈希 哈希槽(哈希碰撞和哈希冲突)

    背景随着memcache和redis的出现,更多人认识到了一致性哈希。一致性哈希用于解决分布式缓存系统中的数据选择节点存储问题和数据选择节点读取问题以及在增删节点后减少数据缓存的消失范畴,防止雪崩的发生。哈希槽是在rediscluster集群方案中采用的,rediscluster集群没有采用一致性哈希方案,而是采用数据分片中的哈希槽来进行数据存储与读取的。一致性哈希一致性hash是一个0-2^32的闭合圆,(拥有2^23个桶空间,每个桶里面可以存储很多数据,可以理解为s3的存储桶)所

    2022年4月14日
    78
  • 360天擎卸载密码忘记了_天擎关闭密码

    360天擎卸载密码忘记了_天擎关闭密码前言MySQL8相比之前版本改动还是挺大的,因为刚从安装接触,就先从基本的说起。现在的mysql8安装只能采用解压配置版,像以前老版本的傻瓜式安装将不复存在。注意点MySQL8之后并不需要my.ini,会自动的生成data文件夹在解压之后的文件,端口默认3306,。若有这个文件,则初始化mysql不成功。自己若新建并设置了my.ini文件,有data文件的话,在初始化之前要删除。然后再初始化在初…

    2022年9月24日
    0
  • jar包如何防止反编译_jar包可以反编译成源码吗

    jar包如何防止反编译_jar包可以反编译成源码吗方法就是,向Jar注入无效代码(不合法的,或者根本不是代码的字符串)。那么无效的代码又怎么能正确运行呢?答案就是,你要保证你的代码永远不会执行到那一步。我作一个简单的例子说明:我们建立一个项目:packagecom.TestJar;publicclassMain{ publicstaticvoidmain(String[]args){ System.out.println(Info.g…

    2022年10月31日
    0
  • Ajax请求的五个步骤[通俗易懂]

    Ajax请求的五个步骤[通俗易懂]Ajax请求的五个步骤一、定义1、什么是AjaxAjax:即异步JavaScript和XML。Ajax是一种用于创建快速动态网页的技术。通过在后台与服务器进行少量数据交换,Ajax可以使网页实现异步更新。这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行更新。而传统的网页(不使用Ajax)如果需要更新内容,必需重载整个网页面。2、同步与异步的区别同步提交:当用户发送请求时,当前页面不可以使用,服务器响应页面到客户端,响应完成,用户才可以使用页面。异步提交:当用户发送请

    2022年5月17日
    58
  • [转][darkbaby]任天堂传——失落的泰坦王朝(下)[通俗易懂]

    [转][darkbaby]任天堂传——失落的泰坦王朝(下)[通俗易懂]即使是日本业界人士也对1999年发生的“口袋妖怪所有权风波”知之甚少,实际上这个事件的结局足以改变游戏产业未来数十年的势力图,山内溥凭借着个人的睿智让任天堂再次渡过了命运的暗礁,而另一颗曾经炙手可热的璀璨明星却从此销声匿迹……   株式会社POKEMON(简称TPC)成立于1998年4月,由任天堂、Creatures、GAMEFREAK三社共同出资组建,该社成立的目的主要是对全球范围的口…

    2022年7月27日
    18
  • js定时器

    js定时器window.setTimeout(code,millisec);//在指定时间后运行window.setInterval(code,millisec);//每过指定时间就运行一次。具体写法如下

    2022年7月1日
    34

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号