将字符串转换为整数数组 jython

0 投票
1 回答
531 浏览
提问于 2025-04-18 01:40
def convertToInteger(stringID):
  id = [0, 1, 2, 3, 4, 5, 6]

我需要使用一个参数 stringID,并把它转换成一个整数形式的数组 id

任何建议都非常感谢!

1 个回答

1

试试这个,使用列表推导式

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]

撰写回答