from operator import itemgetter
from collections import defaultdict
d = defaultdict(list)
for key, value in itertools.groupby(a, itemgetter(0)):
    d[key].append(list(value))
split list by condition in python