鉴于: xs = ['1', '2', '3'] 使用 map 然后 list 获得整数列表: list(map(int, xs)) 在 Python 2 中, list 是不必要的,因为 map 返回了一个列表: map(int, xs) 原文由 cheeken 发布,翻译遵循 CC BY-SA 4.0 许可协议
在列表上使用 列表理解 xs : [int(x) for x in xs] 例如 >>> xs = ["1", "2", "3"] >>> [int(x) for x in xs] [1, 2, 3] 原文由 Chris Vig 发布,翻译遵循 CC BY-SA 4.0 许可协议
鉴于:
使用
map
然后list
获得整数列表:在 Python 2 中,
list
是不必要的,因为map
返回了一个列表: