last = None res = [] for obj in lst: if obj.grp != last: res.append([]) res[-1].append(obj) last = obj.grp