Ali Ali - 5 months ago 31
Python Question

Python Dictionary with dual values key, need to find maximum and minimum value

I have a dictionary with multiple unique key and values of the format {'movieID':[val1,val2]}. I want to print out the movieID with max val1 and min val2. Val1 is rating given by female and Val2 is rating given by male.
Any suggestions/solutions?
Using this in hadoop mapreduce with python mapper and reducer.

Answer Source

You do not need to use hadoop:

>>> data = {'614d5a7ed90f43e5b062dbc3afa7f5b1': [7, 14], 'aa9b80ae387e40f5bc351c3ec3f82143': [9, 7], '49f2c238c2f144fab4468faa091e4620': [13, 18], '1c9ea5622aef41e696102d49eb59691e': [17, 18], '8a86455812eb48e4a7c8b13e55192a3f': [5, 18], 'ad5e4bc4b729432482fec1d03510caee': [8, 9], '6ace5755bff2410db2dcf1a45202b273': [11, 16], '571c38be6f0a4748b2400def38f7443c': [1, 6], 'd110b65111bf4737b3ca5a4c10fbd420': [11, 11], '6f6c930ea04d468c934be7c78a739ec8': [13, 13]}
>>> max(data, key=lambda x: abs(data[x][1]-data[x][0])) #ID with greatest difference
'8a86455812eb48e4a7c8b13e55192a3f'
>>>