How to sort a list of strings on a substring

n00m n00m at
Tue Oct 6 00:45:58 CEST 2009

Here you are:

LogList = [\
    "inbound tcp office inside 88",
    "inbound tcp office inside 2967",
    "inbound udp lab inside 161",
    "inbound udp office inside 53"]

LogList.sort(key=lambda x: x[x.index('1'):])

for item in LogList:
    print item


inbound udp lab inside 161
inbound tcp office inside 88
inbound udp office inside 53
inbound tcp office inside 2967

More information about the Python-list mailing list