I want to sort string array using python.
I have a string array
str_array = {string1, string2, string3}
all string formats are AB-CD-EFGH-IJ-NAME ------> 12-34-5678-09-PHOTO
AB= 00 to 99
CD= 00 to 99
EFGH= 0000 to 9999
IJ= 00 to 99
NAME= any alphabetic name
I want sort string first with there equivalent numeric value (remove “-” from numeric part of string) then alphabetic order.
For example 12-34-5678-09-PHOTO will be 1234568809-PHOTO.
Define a key function which takes an element of the iterable
str_arrayas input, and returns a tuple key consisting of the integer (first) and name (second):For example,
For more on this sorting technique, see the HOWTO Sort wiki.
Note that
sortedreturns a new list. If you wish to sortstr_arrayin-place, then use