I have the following list of lists
listA = [
["4YBB|1|AA|A|262", "4YBB|1|AA|A|263", 'empty', "s35", 'empty', 'empty'],
["4YBB|1|AA|U|261", "4YBB|1|AA|A|263", "tSH", 'empty', 'empty', 'empty'],
["4YBB|1|AA|U|261", "4YBB|1|AA|C|264", "ntSH", 'empty', "5BPh", 'empty'],
["4YBB|1|AA|G|259", "4YBB|1|AA|C|267", "cWW", 'empty', 'empty', 'empty'],
["4WOI|1|DA|A|262", "4WOI|1|DA|A|263", 'empty', "s35", 'empty', 'empty'],
["4WOI|1|DA|C|264", "4WOI|1|DA|G|265", 'empty', "s35", 'empty', 'empty']
]
I would like to group these based on identifiers from another list and they must be ordered the same way as the elements in the identifiers list:
identifiers = ["4YBB|1|AA", "4WOI|1|DA"]
As you can see, the identifiers are subset of the string element 1 and 2 of the inner list. The identifiers will always be the same for element 1 and 2 of the inner list. The desired output is as follows:
desiredoutput = [
[
["4YBB|1|AA|A|262", "4YBB|1|AA|A|263", 'empty', "s35", 'empty', 'empty'],
["4YBB|1|AA|U|261", "4YBB|1|AA|A|263", "tSH", 'empty', 'empty', 'empty'],
["4YBB|1|AA|U|261", "4YBB|1|AA|C|264", "ntSH", 'empty', "5BPh", 'empty'],
["4YBB|1|AA|G|259", "4YBB|1|AA|C|267", "cWW", 'empty', 'empty', 'empty'],
],
[
["4WOI|1|DA|A|262", "4WOI|1|DA|A|263", 'empty', "s35", 'empty', 'empty'],
["4WOI|1|DA|C|264", "4WOI|1|DA|G|265", 'empty', "s35", 'empty', 'empty']
]
]
How can I achieve this using the itertools groupby method or any other methods?