How to sort a list of strings on a substring

n00m n00m at narod.ru
Tue Oct 6 00:45:58 CEST 2009


Here you are:

LogList = [\
    "inbound tcp office 192.168.0.125 inside 10.1.0.91 88",
    "inbound tcp office 192.168.0.220 inside 10.1.0.31 2967",
    "inbound udp lab 172.24.0.110 inside 10.1.0.6 161",
    "inbound udp office 192.168.0.220 inside 10.1.0.13 53"]


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

for item in LogList:
    print item

===========================================================

inbound udp lab 172.24.0.110 inside 10.1.0.6 161
inbound tcp office 192.168.0.125 inside 10.1.0.91 88
inbound udp office 192.168.0.220 inside 10.1.0.13 53
inbound tcp office 192.168.0.220 inside 10.1.0.31 2967



More information about the Python-list mailing list