Q:

How to group a list of tuples based on similar fields and then keep the maximum based on another field? ( without using Pandas)

I have list of tuples like
bottles = [(1234, 'ICED', 'MOC12', 3), (1234, 'ICED', 'MOC12', 2), (3456, 'HOT', 'CAR23', 1), (3456, 'HOT', 'YUP23', 2)]

I want the tuple corresponding to the max of the last field for each groups.  The groups are defined by the first three values. 
Output:
result = [(1234, 'ICED', 'MOC12', 3),(3456, 'HOT', 'CAR23', 1),(3456, 'HOT','YUP23', 2)]

A:

Going by your comment, this should work:
from itertools import groupby

bottles = [(1234, 'ICED', 'MOC12', 3), (1234, 'ICED', 'MOC12', 2), (3456, 'HOT', 'CAR23', 1), (3456, 'HOT', 'YUP23', 2)]
print([max(group) for key, group in groupby(sorted(bottles), lambda a: a[:3])])

