I'm fairly new to Python and still have trouble displaying data that I have in the way that I want. I have this code that determines the most frequent character in a string. However, how I have it prints it as such: ('A', 3)
.
stringToData = raw_input("Please enter your string: ")
import collections
print (collections.Counter(stringToData).most_common(1)[0])
I just wanted some insight into how to manipulate this code to something similar to this:
print "In your string, there are: %s vowels and %s consonants." % (vowels, cons)
Obviously it would say, "In your string, the most frequent character is (character), which occurred (number) times."
I am using Python 2.7, and I tried using the pprint
but I didn't really understand how to incorporate that into my existing code.
Edit: Basically, what I am asking is how I can code finding the most frequent character in a string and printing it in a manner such as "In your string, the most frequent character is (character), which occurred (number) times."