Ich bin mir nicht sicher, ob dies das ist, was Sie wollen, aber dies wird den häufigsten Charakter drucken, der mit der Anzahl der Vorkommen gefolgt ist:
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)
Dies gibt ein Tupel des häufigsten Charakters und der Anzahl der Vorkommen zurück.
collections.Counter(stringToData).most_common(1)[0]
#output: for example: ('f', 5)
Beispiel:
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)
Ausgabe ist:
In your string, the most frequent character is f, which occurred 8 times