Nov-27-2017, 09:00 PM
Using
collections
is probably cheating, but using a dict might be fine:>>> def max_char(string): ... chars = {string.count(ch): ch for ch in string} ... most_used = max(chars.keys()) ... return chars[most_used] ... >>> max_char("foo bar") 'o' >>> max_char("spam eggs") 's' >>> max_char("on a bright sunny day in august") ' 'The important part, is that you actually understand how it works, whichever one you turn in.