def convertToInteger(stringID):
id = [0, 1, 2, 3, 4, 5, 6]
I need to use a parameter stringID
and convert it into the array id
in Integer form.
Any tips would be appreciated!
def convertToInteger(stringID):
id = [0, 1, 2, 3, 4, 5, 6]
I need to use a parameter stringID
and convert it into the array id
in Integer form.
Any tips would be appreciated!
Try this, using list comprehensions:
stringId = '0123456'
[int(x) for x in stringId]
=> [0, 1, 2, 3, 4, 5, 6]
Or alternatively, using map
:
map(int, stringId)
=> [1, 2, 3, 4, 5, 6]