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
what about this? hope this helps.
def k(line): v = line.partition("%")[2] v = v[0] if v else 'z' # here z stands for the max value return v print ''.join(sorted(open('data.txt', 'rb'), key = k))