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

Can´t join a list the way I would like

Why I don´t obtain 1<2<3<6<8 in the image code ? I think it has to do with the string format. If I do type for every element in the list the output is str. But then if after the while I do the following it works fine:
second_list = [str(x) for x in (sorted(lista))]
print("<".join(second_list))

I just don´t really understand why the one in the image doesn´t work:
enter image description here

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 :

str converts the list into its string representation. Use map to convert each number in the list to str:

lista = [1,2,3,4,9,5]
print("<".join(map(str, sorted(lista))))
>>> 1<2<3<4<5<9
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