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.
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)