I have a list of string – ‘starting-list’. The last letters in the elements represents a value. And the other part represent a name. I want to create a list with the unique names.
I can’t use ‘-‘ as split in any straight forward way because it’s not always the last one. The position of the spliting ‘-‘ varies from case to case.
One idea I have is to find the elements that matches in the beginning. And then remove the part that is not the same for all elements. But I can’t figure out how do perform this in code.
Any ideas?
starting_list = ['XX-VAL1',
'XX-VAL-2',
'OPP-VAL-1',
'OPP-VAL2',
'O-PP-VAL1',
'O-PP-VAL2',
'O-PP-VAL3'
'PO-VAL1',
'PO-L-VAL-1',
'PO-L-VAL2',
'RUI-O-VAL1',
'RUI-A-VAL1',
'RUI-O-VAL2',
'RUI-A-VAL2',]
target_list = ['XX', 'OPP', 'O-PP', 'PO', 'RUI-A', 'RUI-B']
1