我已经做了一些挖掘并且大部分使用数组,但我们的类(class)并没有那么远,我们主要使用 for 循环来返回函数中重复次数最多的字母。
到目前为止,这是我的代码,但我所能得到的只是返回第一个字母的计数。
def most_repeated_letters(word_1):
x = 0
z = 0
for letter in word_1:
y = word_1.count(letter[0:])
if y > z:
z = y
x += 1
return z
print most_repeated_letters('jackaby')
最佳答案
from collections import Counter
c = Counter('jackaby').most_common(1)
print(c)
# [('a', 2)]
关于python - 如何在 python 中返回最重复的字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46653281/