Finding modes for multiple dictionary keys
Question: I currently have a Python dictionary with keys assigned to multiple values
(which have come from a CSV), in a format similar to:

    
    
    {
    'hours': ['4', '2.4', '5.8', '2.4', '7'],
    'name': ['Adam', 'Bob', 'Adam', 'John', 'Harry'],
    'salary': ['55000', '30000', '55000', '30000', '80000']
    }
    

(The actual dictionary is significantly larger in both keys and values.)

I am looking to find the mode* for each set of values, with the stipulation
that sets where all values occur only once do not need a mode. However, I'm
not sure how to go about this (and I can't find any other examples similar to
this). I am also concerned about the different (implied) data types for each
set of values (e.g. 'hours' values are floats, 'name' values are strings,
'salary' values are integers), though I have a rudimentary conversion function
included but not used yet.

    
    
    import csv
    
    f = 'blah.csv'
    
    # Conducts type conversion
    def conversion(value):
        try:
            value = float(value)
        except ValueError:
            pass
        return value
    
    reader = csv.DictReader(open(f))
    
    # Places csv into a dictionary
    csv_dict = {}
    for row in reader:
        for column, value in row.iteritems():
            csv_dict.setdefault(column, []).append(value.strip())
    

*I'm wanting to attempt other types of calculations as well, such as averages and quartiles- which is why I'm concerned about data types- but I'd mostly like assistance with modes for now.

EDIT: the input CSV file can change; I'm unsure if this has any effect on
potential solutions.


Answer: I'm not sure I understand the question, but you could create a dictionary
matching each desired mode to those keys, manually, or you could use the
'type' class by asking the values, then if the type returns a string ask other
questions/parameters, like length of the item.

