I don't think reduce is a good tool for this to work, because you have to use itertools first or similarly group the list by key. Otherwise, you will compare cats and dogs , and all hell will break!
Instead, just a simple loop in order:
>>> my_list = [('dog',12,2), ('cat',15,1), ('dog',11,1), ('cat',15,2)] >>> output = {} >>> for animal, high, low in my_list: ... try: ... prev_high, prev_low = output[animal] ... except KeyError: ... output[animal] = high, low ... else: ... output[animal] = max(prev_high, high), min(prev_low, low)
Then, if you want to return the original format:
>>> output = [(k,) + v for k, v in output.items()] >>> output [('dog', 12, 1), ('cat', 15, 1)]
Please note that this will destroy the order from the original list. If you want to keep the order in which the keys first appear, initialize the output with OrderedDict .