['4', '5', '6', '8', '5', '9', '6', '2', '6', '5']
How can I get it to look like this:
[45,68,59,62,65]
How to combine two or more list elements like ['4','5'] to [45]
['4', '5', '6', '8', '5', '9', '6', '2', '6', '5']
How can I get it to look like this:
[45,68,59,62,65]
How to combine two or more list elements like ['4','5'] to [45]
The strategy is to pair the initial data, then convert to int, zip
and slices are a good way dot that
values = ['4', '5', '6', '8', '5', '9', '6', '2', '6', '5']
result = [int(a + b) for a, b in zip(values[::2], values[1::2])]
print(result) # [45, 68, 59, 62, 65]
values[::2]
: one over two ['4', '6', '5', '6', '6']
values[1::2]
: over over two, starting at 2nd ['5', '8', '9', '2', '5']