我有一个看起来像这样的数组:['14', '43.8303', '13', '44.8114', '16', '45.6076', '7', '45.6762', '2', '45.8241', '18', '46.0605', '8', '47.7897', '4', '53.4238', '1', '53.5724', '15', '54.0245', '17', '54.1073', '9', '58.2705', '3', '61.0334', '5', '62.0799', '12', '70.6712', '11', '81.171', '10', '196.992', '6', '314.895']
是否可以将偶数位置的元素转换为int
奇数位置的元素float
?
我试过这样:
for i in range(36):
if i%2==0:
items[i] = map(int, items[i])
else:
items[i] = map(float,items[i])
但是,我收到此错误:
错误消息:ValueError:float()的无效文字: