【问题标题】:Turning a string into an array of integers jython [duplicate]将字符串转换为整数数组 jython [重复]
【发布时间】:2014-04-07 04:44:40
【问题描述】:
def convertToInteger(stringID):
  id = [0, 1, 2, 3, 4, 5, 6]

我需要使用一个参数stringID并将其转换为整数形式的数组id

任何提示将不胜感激!

【问题讨论】:

  • 您能用输入输出示例解释一下吗?

标签: python arrays string integer jython


【解决方案1】:

试试这个,使用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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-28
    • 2019-11-08
    • 2013-10-06
    • 2010-11-21
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    相关资源
    最近更新 更多