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

Convert one element from list to int

I’m searching a way to convert only one element from a list that contain a string and a tuple.

My function returns a list that contains a string and a tuple like that : "[‘X’, ([0], [3])]"

def return_case():
  ...
  case = 1
  return [case, coords_case]

And the goal is that another fonction takes the case[1][0] as an int.

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

Any ideas?

>Solution :

You could have the function take case[1][0] and turn it into an int via case[1][0][0]

For example:

case = ['X', ([25], [3])]
def f(x):
    print(x*x)

f(case[1][0][0])

outputs 625

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