Starting with a sorted iterable object I need to group the items by their first character (say a group for every letter from a to z and a group for numbers and symbols).
For a more concrete example, let’s say I have this list:
L = [‘aa’, ‘ab’, ‘ac’, ‘ba’, ‘bb’, ‘bc’, ‘ca’, ‘cb’, ‘cc’, ’10’, ‘%a’, ‘ b’, …]
And I need something like:
GL = [[‘aa’, ‘ab’, ‘ac’], [‘ba’, ‘bb’, ‘bc’], [‘ca’, ‘cb’, ‘cc’], [’10’, ‘%a’, ‘ b’]]
What are the options for doing so, and which is the most efficient?
returns:
You can use something else instead of
'}'to put all non-alpha-characters at the correct position in the sorting.