python 統計字元頻次

2021-10-09 07:40:51 字數 587 閱讀 4605

統計字元頻次

輸入乙個字串,輸出其**現次數最多的字元及其出現的次數,要求使用字典。

輸入格式:

輸入任意長度字串。

輸出格式:

字串**現次數最多的字元及其次數。

輸入樣例:

在這裡給出一組輸入。例如:

abcdsekjsiejdlsjdiejsl
輸出樣例:

在這裡給出相應的輸出。例如:

('s', 4)
python**:

from collections import counter

a=input()

b=counter(a)

b.items()

c=str(b.most_common(1))

out=c.replace('[','').replace(']','')

print(out)

python例項 元組命名 頻次統計 字典排序

1.為元組中元素命名 方法1.定義常量 name,age 0,1 student 喬峰 29,qf jinyong.com name student name age student age 方法2.使用 namedtuple from collections import namedtuple s...

python例項 元組命名 頻次統計 字典排序

1.為元組中元素命名 方法1.定義常量 name,age 0,1 student 喬峰 29,qf jinyong.com name student name age student age 方法2.使用 namedtuple from collections import namedtuple s...

python做統計字元 python統計字元個數

python count 方法 描述python count 方法用於統計字串裡某個字元出現的次數。可選引數為在字串搜尋的開始與結束位置。語法count 方法語法 str.count sub,start 0,end len string 複製 引數sub 搜尋的子字串 start 字串開始搜尋的位置...