Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 我只想在python中更改列表中某些元素的数据类型_List_Type Conversion - Fatal编程技术网

List 我只想在python中更改列表中某些元素的数据类型

List 我只想在python中更改列表中某些元素的数据类型,list,type-conversion,List,Type Conversion,我有一个列表,里面有这样的东西 [['11.0' 'Switchgear and Protection' '' '' '' '25569.0' '26299.0'] ['12.0' 'Synchronising' '' '' '' '25569.0' '26299.0'] ['13.0' 'Transformers and Protection' '' '' '' '25569.0' '26299.0'] ['14.0' 'Turbine' '' '' 'Name' '25569.0'

我有一个列表,里面有这样的东西

 [['11.0' 'Switchgear and Protection' '' '' '' '25569.0' '26299.0']
 ['12.0' 'Synchronising' '' '' '' '25569.0' '26299.0']
 ['13.0' 'Transformers and Protection' '' '' '' '25569.0' '26299.0']
 ['14.0' 'Turbine' '' '' 'Name' '25569.0' '26299.0']
 ['15.0' 'Cooling Water' '' '' '' '25569.0' '26299.0']
 ['16.0' 'Water Cycle' '' '' '' '25569.0' '26299.0']]
我想将第一个和最后两个冒号更改为int类型,但未成功。(学习一门新语言并不是人们所说的全部…)

谢谢
保罗

这里有一种可能的方法:

listoflists=[ ['11.0', 'Switchgear and Protection', '', '', '', '25569.0', '26299.0'],
              ['12.0', 'Synchronising', '', '', '', '25569.0', '26299.0'],
              ['13.0', 'Transformers and Protection', '', '', '', '25569.0', '26299.0'],
              ['14.0', 'Turbine', '', '', 'Name', '25569.0', '26299.0'],
              ['15.0', 'Cooling Water', '', '', '', '25569.0', '26299.0'],
              ['16.0', 'Water Cycle', '', '', '', '25569.0', '26299.0'] ]
for i in xrange(len(listoflists)):
    for j in xrange(len(listoflists[i])):
        try:
            listoflists[i][j] = int(float(listoflists[i][j]))
        except:
            pass

我不确定是否有更简单的方法。

欢迎来到Stack Overflow,请[参观](),确保您阅读并更新了您的问题,了解更多信息。