av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Python程序:計(jì)算字符串中的字符頻率

創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)于2013年成立,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站制作、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元南山做網(wǎng)站,已為上家服務(wù),為南山各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792

編寫(xiě)一個(gè) Python 程序,使用 for 循環(huán)和字典來(lái)計(jì)算字符串中的字符頻率。在這個(gè) Python 示例中,for 循環(huán)迭代整個(gè)字符串。我們把所有的字符數(shù)分配給字典鍵。

# Count Charcaters Frequency in a String

string = input("Please enter the Your Own String = ")
chardict = {}

for num in string:
    keys = chardict.keys()
    if num in keys:
        chardict[num] += 1
    else:
        chardict[num] = 1

print(chardict)

這個(gè) Python 程序使用 Counter 集合對(duì)給定字符串中的所有字符頻率進(jìn)行計(jì)數(shù)。

# Count Charcaters Frequency in a String

from collections import Counter

string = input("Please enter the Your Own String = ")

chars = Counter(string)

print("Total Characters Frequency in this String = ")
print(chars)
Please enter the Your Own String = hello python programmers
Total Characters Frequency in this String = 
Counter({'o': 3, 'r': 3, 'h': 2, 'e': 2, 'l': 2, ' ': 2, 'p': 2, 'm': 2, 'y': 1, 't': 1, 'n': 1, 'g': 1, 'a': 1, 's': 1})

本文名稱(chēng):Python程序:計(jì)算字符串中的字符頻率
文章來(lái)源:http://uogjgqi.cn/article/dhjgjop.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢(xún)/運(yùn)營(yíng)咨詢(xún)/技術(shù)建議/互聯(lián)網(wǎng)交流