I am trying to convert ['1','2','3','4'] to [1,2,3,4] I want to make this conversion inplace. Is it possible to do it? If not, what is the optimal solution.
I think it is better to use map for this kind of tasks. Which creates iterator, what means it is more memory efficient.
l = list(map(int, l))
# here I convert it to list, but usually you would just iterate over it
# so you can just do
for item in map(int, l):
...
you can do it with list comprehension like this:
l = [int(item) for item in l]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With