Contents
- Grouping by equality
- The
key
parameter
The itertools groupby
function divides a sequence into contiguous subsequences where the elements in each subsequence share something in common.
Grouping by equality
When used with a single parameter, groupby
itertools.groupby
finds groups of repeated elements.The reason this function is named “groupby” instead of “group” won’t become clear until we discuss the optional key
parameter.