In python I have the following array:
['75920-c1-u1 .pdf', '75920-c1-u2 .pdf', '75920-c1-u3 .pdf', '75920-c1-u4 .pdf', '75920-c1-u5 .pdf' , '75920-c1.pdf']
I would like to make the element: 75920-c1.pdf be on the index 0 and after it the rest should follow, so 75920-c1-u1 .pdf, 75920-c1-u2 .pdf etc…
I can’t even manage to do this…
>Solution :
ls = ['75920-c1-u1 .pdf', '75920-c1-u2 .pdf', '75920-c1-u3 .pdf', '75920-c1-u4 .pdf', '75920-c1-u5 .pdf' , '75920-c1.pdf']
ls.sort(key=lambda s:(len(s),s))
# ls = ['75920-c1.pdf', '75920-c1-u1 .pdf', '75920-c1-u2 .pdf', '75920-c1-u3 .pdf', '75920-c1-u4 .pdf', '75920-c1-u5 .pdf']