I have this list of numbers in python
['1', '0', '0', '0', '1', '1', '4']
And I want to turn it into this format (tuple of int).
(1, 0, 0, 0, 1, 1, 4)
How can I do it?
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)
You could use list comprehension:
nums_list = ['1', '0', '0', '0', '1', '1', '4']
nums_tuple = tuple([int(x) for x in nums_list])
print(nums_tuple) # (1, 0, 0, 0, 1, 1, 4)
you can use the method below
nums_list = ['1', '0', '0', '0', '1', '1', '4']
nums_tuple = tuple(int(x) for x in nums_list)
print(nums_tuple)
(1,1,0)is a tuple while[1,1,0]is a list, it's similar but they have differences explained here better than I would do