Code:
charlist = [0 for i in xrange(27)]
while True:
inputtext = raw_input("Please input some text: ")
for character in inputtext:
av = ord(character)
if av >= 65 and av <= 90:
charlist[ord(character)-64] += 1
elif av >= 97 and av <= 122:
charlist[ord(character)-96] += 1
elif av==33:
break
if av==33: break
maxi = max(charlist)
print 'num_max =',maxi
print 'max_occur =',charlist.count(maxi)
print 'most_common =',map(lambda x: chr(x+64), filter(lambda x: charlist[x]==maxi, range(27)))
I don't know all the terms of your assignment, so I just did this the way that I would actually code it.
Okay now lets study this program.
First we held open a character list. I would seed it by 0 but since you wanted to seed it so that a=1, that is fine too.
We knew we would have to keep asking the user for text until we knew to stop, so we started with a while loop. Next we took raw input. We did not use input( ..) because it was not guaranteed to be of type string, which could hurt us in comparison later (for example, "for character in inputtext" may not work because inputtext is not an iterable.)
Now we looked at each character in the input text. This was the right approach and you did a good job. Had you looked for the number of "a"s in inputtext, then followed by the number of "b"s, etc. you would have made a quadratic number of comparisons instead of a linear amount.
So, for each character we stored the ordinal number in a variable "av", so we would not have to look it up each time. We then checked if it was in the range [65,90] which would make it a capital letter from A-Z. If it was, we ticked up our charlist. We did the same in checking for lowercase. Finally, we knew the ordinal number of "!" would be ord("!") == 33, so if that were true, we stopped looking at letters immediately. (So if you type xyzz!aaaaaaa, "a" wont be most common.)
Finally, we checked if the residue on "av" was still 33. This is not that great of a practice but for something like this IMO it is fine. If and only if we saw a "!" (if character == "!"), the control structure would break out at the "elif av==33: break" part, and then it would immediately break out again at "if av==33: break".
Now we come to reporting the result. The num_max is simply going to be the highest number in our tally (namely, charlist). The number of times the max occurs is going to be charlist.count(maxi) -- this just counts how many times maxi was seen. The last one is tricky, so lets look at it in two steps:
First, we want a list of indices that represent the letters that are most common. For example if A, B, and D are most common, we want a list of [1,2,4]. The appropriate code for this is "filter(lambda x: charlist[x]==maxi, range(27))". What that does is, it takes a list [0,1,2,...,26], and it only keeps the elements of the list x for which charlist[x] == maxi -- namely, that it was a maximum.
Secondly, we have this list (eg. nicelist = [1,2,4]) and we want to get to ['A','B','D']. The correct code is going to be map(lambda x: chr(x+64), nicelist). What that does is, it goes one by one down nicelist and it changes every element x to chr(x+64). Since each element can only be a number from 1 to 26, it will change everything to one of chr(65) = 'A', chr(66) = 'B', etc. up to chr(90) = 'Z'.
Putting it together, we get this chunky line "map(lambda x: chr(x+64), filter(lambda x: charlist[x]==maxi, range(27)))".
If list comprehensions are new to you, you can iterate through the list and use the same ideas.
Code:
common = []
for i in xrange(len(charlist)):
if charlist[i]==maxi: common.append(chr(64+i))
print common
I hope that helps, if you told me the assignment more maybe I can help you more simply.