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.
itertools.groupby
Link to my previous tips on itertools.
Python-Magic: Reliable File Type Detection Beyond Extensions
Hydra: YAML-Based Config Management Made Simple
Loguru: Configure Professional Logging in a Single Line
Your email address will not be published. Required fields are marked *
Name
Email
Website
Save my name, email, and website in this browser for the next time I comment.
Δ