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 convert numeric string from a sublist in Python

I’m a freshie. I would like to convert a numeric string into int from a sublist in Python. But not getting accurate results. 😔

countitem = 0
list_samp = [['1','2','blue'],['1','66','green'],['1','88','purple']]

for list in list_samp:
  countitem =+1
  for element in list:
    convert_element = int(list_samp[countitem][0])
    list_samp[countitem][1] = convert_element

>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

You can do it like this:

list_samp = [['1','2','blue'],['1','66','green'],['1','88','purple']]
me = [[int(u) if u.isdecimal() else u for u in v] for v in list_samp]
print(me)
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