I have a text file that looks a bit like:
random text random text, can be anything blabla %A blabla
random text random text, can be anything blabla %D blabla
Here is a quick-and-dirty approach. Without knowing more about the requirements of your sort, I can't know if this satisfies your need.
Assume that your list is held in 'listoflines
':
listoflines.sort( key=lambda x: x[x.find('%'):] )
Note that this will sort all lines without a '%' character by their final character.