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

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

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

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

英文词频统计实例

待分析字符串

分解提取单词

大小写 txt.lower()

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

计数字典

排序list.sort()

输出TOP(10)

 

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

number=int(input("输入分数:"))
score=list('46132186716321')
score.append(number)
print("第一个3分的下标是:{}".format(score.index('3')))
print("1分的统计是:{}".format(score.count('1')))
print("3分的统计是:{}".format(score.count('3')))

 

 

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

 

 

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

ls=list("abcdefghijklmnopqrstuvwxyz")
tu=tuple("abcdefghijklmnopqrstuvwxyz")
di={'语文':1,"数学":2,"英语":3,"物理":4,"化学":5,"生物":6}
se=set("123131321")
for i in tu:
    print(i)

 

 

 

 英文词频统计

news='''"President tells officials at conference to focus on safety, where the public has noted improvement

President *** has called for more systematic and innovative social governance, stressing the need to improve the capability to predict and prevent security risks.

Xi, general secretary of the Communist Party of China Central Committee, was speaking on Tuesday at a Beijing conference to award individuals and units that have made outstanding contributions to the public security governance sector in the past five years.

Since late 2012, people working in political and legal affairs have innovated social governance methods and dealt with large numbers of outstanding problems, making the general public feel safer, he said.

The sense of security of the Chinese public has increased from 88 percent in 2012 to 92 percent in 2016, according to data released on Tuesday by the Central Committee for Comprehensive Management of Public Security, a central level authority in charge of social governance in China.

However, Xi wants more effort to be taken to build a safer China. The authorities involved should be aware of the difficulties and challenges, carefully analyze the current situation of Chinese society, adopt technological innovation methods and improve the capacity to forecast and prevent risks, he said.

Xi also stressed that social governance officers should have a better sense of the rule of law.

More than 500 members from central and local political and law departments, as well as outstanding individuals and units, are participating in the two-day meeting, which concludes on Wednesday.

"I'm excited and inspired after listening to the president's remarks, which made a comprehensive summary of social governance in the past five years and outlined the new requirements and tasks in the future," said Huang Ming, vice-minister of public security.

Huang said the most valuable lesson he has learned is to go with the "innovative ideas and strategies to tackle the issues involving social security and win the support of the people".

He Wenhao, a senior official in charge of political and legal affairs in the Tibet autonomous region who attended the conference, said the president's speech has built up his confidence in safeguarding Tibet.

He said the biggest challenge he now faces is fighting "the separatist forces to ensure the continuous safety and stability in Tibet"."'''

news=news.lower()
for i in ',.?"':
    news=news.replace(i," ")
words=news.split(" ")
word = set(words)
dic={}
for i in word:
    dic[i]= words.count(i)
    
words=list(dic.items())
words.sort(key=lambda x:x[1],reverse=True)
print(words)
for i in range(10):
    word,count=words[i]
    print("{} {}".format(word,count))

posted @ 2017-09-20 20:23  44卢全浩  阅读(262)  评论(0编辑  收藏  举报