itertools.groupby: Group Elements in an Iterable by a Key
itertools.groupby: Group Elements in an Iterable by a Key
If you want to group elements in a list by a key, use itertools.groupby. In the example above, I grouped elements in the list by the first element in each tuple.