Finding the most frequent character in a string

前端 未结 10 1919
执笔经年
执笔经年 2020-12-03 21:54

I found this programming problem while looking at a job posting on SO. I thought it was pretty interesting and as a beginner Python programmer I attempted to tackle it. Howe

10条回答
  •  长情又很酷
    2020-12-03 22:29

    Here's a way using FOR LOOP AND COUNT()

    w = input()
    r = 1
    for i in w:
        p = w.count(i)
        if p > r:
            r = p
            s = i
    print(s)
    

提交回复
热议问题