if my list is
B = ['1,222,000', '234,444', '12,000,000']
how do I convert that to
[1222000, 234444, 12000000]
I tried
B = list(map(int, B)
but it gives the error,
invalid literal for int() with base 10: '1,375,178'
Remove the commas first like this:
B = [int(i.replace(',', '')) for i in B]
You can also use regular expressions and map
:
import re
B = ['1,222,000', '234,444', '12,000,000']
new_b = list(map(lambda x:int(re.sub('\W+', '', x)), B))
Output:
[1222000, 234444, 12000000]