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
random text random text, can be anything blabla blabla %F
random text random text, can be anything blabla blabla
random text random text, %C can be anything blabla blabla
When I readlines()
it in, it becomes a list of sentences. Now I want this list to be sorted by the letter after the %
. So basically, when the sort is applied to the above, it should look like:
random text random text, can be anything blabla %A blabla
random text random text, %C can be anything blabla blabla
random text random text, can be anything blabla %D blabla
random text random text, can be anything blabla blabla %F
random text random text, can be anything blabla blabla
Is there a good way to do this, or will I have to break each string in to tubles, and then move the letters to a specific column, and then sort using key=operator.itemgetter(col)
?
Thank you