1 2 3 4 5 6 7
last = None res = [] for obj in lst: if obj.grp != last: res.append([]) res[-1].append(obj) last = obj.grp