【发布时间】:2014-04-07 04:44:40
【问题描述】:
def convertToInteger(stringID):
id = [0, 1, 2, 3, 4, 5, 6]
我需要使用一个参数stringID并将其转换为整数形式的数组id。
任何提示将不胜感激!
【问题讨论】:
-
您能用输入输出示例解释一下吗?
标签: python arrays string integer jython
def convertToInteger(stringID):
id = [0, 1, 2, 3, 4, 5, 6]
我需要使用一个参数stringID并将其转换为整数形式的数组id。
任何提示将不胜感激!
【问题讨论】:
标签: python arrays string integer jython
试试这个,使用list comprehensions:
stringId = '0123456'
[int(x) for x in stringId]
=> [0, 1, 2, 3, 4, 5, 6]
或者,使用map:
map(int, stringId)
=> [1, 2, 3, 4, 5, 6]
【讨论】: