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

How to replace multiple unsorted list elements at once in the simplest way?

I would like to write the code below in the simplest way possible. It can be written better for sure. Such a record itches. How can I do it?

table_body_line_striped_typed = [float(argument) for argument in table_body_line_striped]
table_body_line_striped_typed[0] = int(table_body_line_striped_typed[0])
table_body_line_striped_typed[1] = int(table_body_line_striped_typed[1])
table_body_line_striped_typed[4] = int(table_body_line_striped_typed[4])
table_body_line_striped_typed[5] = int(table_body_line_striped_typed[5])
table_body_line_striped_typed[8] = int(table_body_line_striped_typed[8])

>Solution :

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

I hope this is simple enough

table_body_line_striped_typed = [float(argument) for argument in table_b]
for index in [0,1,4,5,8]:
    table_body_line_striped_typed[index] = int(table_body_line_striped_typed[index])

you can also use this one-liner for the same result:

table_body_line_striped_typed = [float(arg) if i in [0,1,4,5,8] else int(arg) for i,arg in enumerate(table_b)] 
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