make a list of lists in which each list `g` are the elements from list `test` which have the same characters up to the first `_` character
[list(g) for _, g in itertools.groupby(test, lambda x: x.split('_')[0])]