이것이 당신이 원하는 것인지 확실하지 않지만 이것은 가장 빈번한 캐릭터를 인쇄 한 다음 발생 수를 인쇄합니다.
import collections
char, num = collections.Counter(stringToData).most_common(1)[0]
print "In your string, the most frequent character is %s, which occurred %d times" % (char, num)
이것은 가장 빈번한 캐릭터의 튜플과 발생 횟수를 반환합니다.
collections.Counter(stringToData).most_common(1)[0]
#output: for example: ('f', 5)
예시:
stringToData = "aaa bbb ffffffff eeeee"
char, num = collections.Counter(stringToData).most_common(1)[0]
print "In your string, the most frequent character is %s, which occurred %d times" % (char, num)
출력은 다음과 같습니다.
In your string, the most frequent character is f, which occurred 8 times