Sort a list of strings based on regular expression match

后端 未结 4 498
别跟我提以往
别跟我提以往 2021-01-14 02:33

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         


        
4条回答
  •  无人共我
    2021-01-14 03:22

    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))
    

提交回复
热议问题