-1

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'

Conor
  • 39
  • 1
  • 9

2 Answers2

4

Remove the commas first like this:

B = [int(i.replace(',', '')) for i in B]
jpp
  • 159,742
  • 34
  • 281
  • 339
0

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]
Ajax1234
  • 69,937
  • 8
  • 61
  • 102