Changelog grouping by component

Write codeEasy15 min

Your task

A release note generator groups changelog entries by component before it prints. entries holds one change per string, written as the component, then a vertical bar, then the summary. The component is everything before the first bar, so a summary is free to contain bars of its own, and every entry carries at least one bar. Components compare exactly, which makes API and api two different components. Return the entries regrouped so that all the entries of one component sit together, with the components in the order their first entry appeared in the changelog, and the entries inside a component kept in the order they were written. Nothing is dropped and nothing is rewritten. An empty changelog returns an empty list.

Examples

group_by_first_seen(entries: list[str]) -> list[str]
Example 1
Inputgroup_by_first_seen(["api|add pagination", "cli|new flag", "api|fix 500", "docs|typo"])
Output["api|add pagination", "api|fix 500", "cli|new flag", "docs|typo"]
Example 2
Inputgroup_by_first_seen(["b|two", "a|one", "b|three", "a|four"])
Output["b|two", "b|three", "a|one", "a|four"]
Example 3
Inputgroup_by_first_seen(["ui|dark mode", "ui|spacing"])
Output["ui|dark mode", "ui|spacing"]