python - Sorting list of strings based on substring in each string -


i have list below:

 = ['e8:04:62:23:57:d0\t2462\t-55\t[wpa2-psk-ccmp][ess]\ttest', '00:1b:2f:48:8b:f2\t2462\t-57\t[wpa2-psk-ccmp-preauth][ess]\tt_test', 'e8:04:62:23:4e:70\t2437\t-61\t[wpa2-psk-ccmp][ess]\tt_guest', 'e8:04:62:23:57:d1\t2462\t-53\t[ess]\t', 'e8:04:62:23:4e:71\t2437\t-56\t[ess]\t'] 

i want sort list based on numbers after third tab of each element, in case -55, -57, -61, -53 should change list order -53, -55, -57, -61. way have tried seems convoluted (making list of lists , on). should using regex/pattern simplify this?

you can pass in custom lambda here sorted function desired result:

>>> = ['e8:04:62:23:57:d0\t2462\t-55\t[wpa2-psk-ccmp][ess]\ttest', '00:1b:2f:48:8b:f2\t2462\t-57\t[wpa2-psk-ccmp-preauth][ess]\tt_test', 'e8:04:62:23:4e:70\t2437\t-61\t[wpa2-psk-ccmp][ess]\tt_guest', 'e8:04:62:23:57:d1\t2462\t-53\t[ess]\t', 'e8:04:62:23:4e:71\t2437\t-56\t[ess]\t'] >>> sorted(a, key = lambda x: int(x.split("\t")[2]), reverse=true) ['e8:04:62:23:57:d1\t2462\t-53\t[ess]\t', 'e8:04:62:23:57:d0\t2462\t-55\t[wpa2-psk-ccmp][ess]\ttest', 'e8:04:62:23:4e:71\t2437\t-56\t[ess]\t', '00:1b:2f:48:8b:f2\t2462\t-57\t[wpa2-psk-ccmp-preauth][ess]\tt_test', 'e8:04:62:23:4e:70\t2437\t-61\t[wpa2-psk-ccmp][ess]\tt_guest'] 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -