0

I have the following str

tmp=
'794 795 1005 1006 1017 1018 1048 1077 '

I want to convert it to a list or an array of integers.

I tried the followings:

[int(x) for x in tmp]

ValueError: invalid literal for int() with base 10: ''

and

map(int, tmp) 

ValueError: invalid literal for int() with base 10: ''
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
emax
  • 6,965
  • 19
  • 74
  • 141
  • Note that the commonly used built-in type is called a *list*, not an array. Arrays do exist in Python, but are a different beast, see the [`array` module](https://docs.python.org/2/library/array.html). – Martijn Pieters Apr 20 '16 at 16:21
  • You should `split` the array separated by spaces and then convert into `int`. – letmutx Apr 20 '16 at 16:21

0 Answers0