Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python change index for value array

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…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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']

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading