لست متأكدًا مما إذا كان هذا هو ما تريده ، لكن هذا سيطبع الشخصية الأكثر شيوعًا المتبعة بعدد الحوادث:
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