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

    1. 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
    2. 字典实例:建立学生学号成绩字典,做增删改查遍历操作。
    3. 列表,元组,字典,集合的遍历。
      总结列表,元组,字典,集合的联系与区别。
    4. 英文词频统计实例
      1. 待分析字符串
      2. 分解提取单词
        1. 大小写 txt.lower()
        2. 分隔符'.,:;?!-_’
      3. 计数字典
        1. 排除语法型词汇,代词、冠词、连词

      4. 排序list.sort()
      5. 输出TOP(10)

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

>>> fen = list('123321213231')
>>> print('fen')
fen
>>> print(fen)
['1', '2', '3', '3', '2', '1', '2', '1', '3', '2', '3', '1']
>>> fen.count('1')
4
>>> fen.count('3')
4
>>> fen.index('3')
2
>>> 

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

>>> score = {'1':90,'2':92,'3':94,'4':100}
>>> print('成绩表:',score.items())
成绩表: dict_items([('1', 90), ('2', 92), ('3', 94), ('4', 100)])
>>> score['5']='96'
>>> print('添加学号为5的学生成绩:',score.items())
添加学号为5的学生成绩: dict_items([('1', 90), ('2', 92), ('3', 94), ('4', 100), ('5', '96')])
>>> score['2']='93'
>>> print('修改学号为2学生的成绩后的成绩表:',score.items())
修改学号为2学生的成绩后的成绩表: dict_items([('1', 90), ('2', '93'), ('3', 94), ('4', 100), ('5', '96')])
>>> 

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

 列表/元组/集合/字典的理解

(1)列表是任意对象的序列。列表用方括号表示。

(2)将一组值打包到一个对象中,称为元组。元组用圆括号表示。元组和列表的大部分操作相同。但是,列表是不固定的,可以随时插入,删除;而元组一旦确认就不能够再更改。所以,系统为了列表的灵活性,就需要牺牲掉一些内存;而元组就更为紧凑。(注意,元组在定义过程中,字符串必须用单引号‘扩起来。)

(3)与列表和元组不同,集合是无序的,也不能通过索引进行访问。此外,集合中的元素不能重复。

(4)字典就是一个关联数组或散列表,其中包含通过关键字索引的对象。用大括号表示。与集合相比,通过关键字索引,所以比集合访问方便。字典是Python解释器中最完善的数据类型。

 

4、字符练习:

news = '''Ready to Download iOS 11 to Your iPhone or iPad? Read This First.
You'll get a fresh look, a smarter version of Siri, and some new Live Photos tricks
By Bree Fowler
September 19, 2017
    
Friday officially marks the start of fall, that time of year when you start seeing pumpkin spice lattes and new iPhones. And for iPhone users who don’t plan on buying a new smartphone anytime soon, it’s time to update your iOS.

With the iPhone 8 and 8 Plus set to go on sale Friday, Apple is rolling out iOS 11, which includes a handful of new features, both fun and practical, along with a fresh look. And if you have an iPad, you can update that, too.

Here’s a quick look at how to update and what you can expect once you do. 

Buy right every time
Subscribe for unlimited access to ratings and reviews
Subscribe
Back It Up
Updates don’t always go perfectly, though chances are everything will be fine. Still, if something does go wrong, you’ll want to restore your phone’s data with a backup copy.

You can back your phone up either to the cloud or to your computer’s hard drive through iTunes. In both cases, make sure you have enough storage. When you sign up for iCloud, Apple gives you just 5GB of storage free. Most people have far more than that stored on their iPhones. If you need more space, you’re going to have to pay.

If you plug your phone into your computer and fire up iTunes, you can see when your phone was last backed up and whether to your computer or the cloud. The same screen gives you the option of manually backing up your phone to either place. Go ahead and do that.

 iOS 11 screenshots 
Apple has been promoting a new App Store look, a smarter Siri, and peer-to-peer payments through iMessage—but that didn't launch with iOS 11.
The Actual Update
Once the phone is backed up, tap the Settings icon, and after it opens up select General. From there, Software Update is the second item from the top.

You’ll probably see a notification that an update is ready. If not, select Software Update anyway and your phone will search for the update. Then just download and install it. This could take several minutes.

Make sure your battery is close to fully charged before you start, or plug your phone in. Upgrading takes a lot of juice. You’ll also need about 2GB of free storage to run the update, so start deleting stuff now if you need to.

According to Apple, iOS 11 is compatible with every iPhone dating back to the 5s. But smartphones have advanced quite a bit in the four years since that phone debuted. If you have an iPhone 5s, it won’t freeze up once you download the new operating system. However, it may not have the horsepower to run every advanced feature that requires a lot of processing power.

What's New?
The first thing you’ll probably notice after the update completes and your phone restarts is the redesigned Control Center. You can customize it to include only the controls you want or need.

Some users may want to beef up their Control Center with the remote app for an Apple TV, or access to iOS 11’s new “Do Not Disturb While Driving” mode. But if you’re content with familiar functions for the flashlight, camera controls, and so on, those are still included.

Camera updates include new filters, such as Vivid, which makes colors pop, and some new tricks for Live Photo, which was introduced with iOS 9 in 2015. As a reminder, Live Photo captures a tiny video clip when you take a still photo to create just a hint of movement. With iOS 11 you can easily convert a Live Photo into a short video loop that you can share on social media or email. 

And Siri has been updated to sound more human and, according to Apple, to be more intelligent. The information the digital assistant collects about you will be used to autofill your iMessages with what it thinks you’re going to say, according to the company. It will also fill out your Safari web searches and suggest news articles. The more you use Siri, the better it is supposed to get at anticipating what you want to do.

One of the most useful and long-awaited features of iOS 11 was supposed to be person-to-person payments through iMessage, as many people already use third-party apps such as Venmo. But this feature isn’t ready quite yet. On its website, Apple says to expect it sometime this fall.

But some other apps are now connected to iMessage in the form of a crawl of little icons below the spot where you type. Want to let someone know where you are? Embed a Google Map showing your location. And though you can’t send your friend the $20 you owe her just yet, you can send a gift card from companies such as Seamless and Starbucks. And, yes, there are more stickers and emojis, too.

Finally, Apple has launched a new design of the app store with iOS 11. It has a more curated feel than before, with separate sections for what’s new in the store, as well as Apple’s recommended apps and games. '''
news = news.lower()
news = news.replace(',','')
news = news.replace('.','')
news = news.replace('?','')
words = news.split(' ')

key = set(words)
exc = ('and','the','to','is','it','of')
for q in exc:
    key.remove(q)
w={}
for i in key:
    w[i]=words.count(i)
wc = list(w.items())
wc.sort(key=lambda x:x[1],reverse=True)
print(wc)

ww = wc[:10]
print(ww)

结果:

已经排除掉('and','the','to','is','it','of')等比较频繁出现的词语。词频TOP 10

完成!!!!

 

posted @ 2017-09-21 21:17  410陈锐锦  阅读(241)  评论(0编辑  收藏  举报