組合數據類型練習,英文詞頻統計實例上

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.pswp.cn/news/540583.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540583.shtml
英文地址,請注明出處:http://en.pswp.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;很多…