2017-03-28 94 views
0

我有一個名爲newlist轉換字符串元素在python

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]]. 

任何人都可以幫助我。

回答

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 
+0

謝謝You.The代碼解決了我的問題列表 – mira