# Author: Scott Wehrwein
# Date: 2/27/23
# L17 P1

def charcount(in_string):
    """ Return a dictionary that maps each unique character in 
    in_string to the number of times it appears in the string.
    Precondition: in_string is a string
    Example: count("hahah") # => {"a": 2, "h": 3} """
    
    count = {}
    
    for c in in_string:
        count[c] = count.get(c, 0) + 1
        
        # or:
#         if c in count:
#             count[c] += 1
#         else:
#             count[c] = 1
    
    return count

def strmode(in_str):
    """ Return the most frequently-appearing character in   
    in_str, or any of the most frequent characters in case of a
    tie. Precondition: in_str is a string with nonzero length.
    Examples: strmode('hahah') # => 'h'
              strmode('who') # => could return 'w', 'h', or 'o'
    """
    
    counts = charcount(in_str)
    
    biggest = 0
    biggest_c = ""
    for k, v in counts.items():
        if v > biggest:
            biggest = v
            biggest_c = c

    return c