将列表中的字符串元素转换为python中的整数

时间:2017-03-28 13:41:43

标签: string list int

我有一个名为newlist的列表

newlist=[['24,4,17,46,0,43'], ['11,43,17'], ['33,17,43,4'], ['74,21'],['21,43,43,74,68,21']]

我需要将每个列表元素转换为integers.i.e。

newlist=[[24,4,17,46,0,43], [11,43,17], [33,17,43,4], [74,21], [21,43,43,74,68,21]].

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

Python 3:

newlist=[['24,4,17,46,0,43'], ['11,43,17'], ['33,17,43,4'], ['74,21'],['21,43,43,74,68,21']]
mylist = list(map(lambda x : list(map(int, x[0].split(','))) , newlist))
print(mylist)

Python 2:

newlist=[['24,4,17,46,0,43'], ['11,43,17'], ['33,17,43,4'], ['74,21'],['21,43,43,74,68,21']]
mylist = map(lambda x : map(int, x[0].split(',')) , newlist)
print mylist