There is such a list containing dictionaries:
list_param = [{'company': 'Apple', 'tariff_rate': Decimal('3.00')}, {'company': 'Apple', 'tariff_rate': Decimal('4.00')}, {'company': 'Apple', 'tariff_rate': Decimal('3.00')}] Moreover, companies can be many different, you need to find the same ratio for the same ones.
I have the following:
def comparison_rate(d, x): k = x['company'] if k in d: d[k]['tariff_rate'] = max(x['tariff_rate'] for k in d) else: d[k] = x return d tariff = reduce(comparison_rate, list_param, {}).values() Gives just the latest dictionary, in this case with a factor of 3.0
print(tariff) [{'tariff_rate': Decimal('3.00'), 'company': 'Apple'}] Python 3.5. Thank you in advance.