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: List in python turn into a specific format

I’m new in python.

I have this list of numbers in python

['1', '0', '0', '0', '1', '1', '4']

This format what I need.

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

And then I want to turn this into a value of a variable.

(1,0,0,0,1,1,4)

What should I do make this happen?. Thankyou!

>Solution :

You could use map:

>>> nums_list = ['1', '0', '0', '0', '1', '1', '4']
>>> nums_tuple = tuple(map(int, nums_list))
>>> nums_tuple
(1, 0, 0, 0, 1, 1, 4)

Or a comprehension:

>>> nums_tuple = tuple(int(x) for x in nums_list)
>>> nums_tuple
(1, 0, 0, 0, 1, 1, 4)
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