我想進行運算 但我要轉成float 要如何比較方便
print(collected_list)
[[('0.017', '0.107'), ('0.018', '0.115'), ('0.019', '0.113'), ('0.02', '0.109')], [('0.067', '0.218'), ('0.068', '0.253'), ('0.069', '0.234'), ('0.07', '0.182')]]
我要把它變成 float 來做運算 請問可以直接從這邊做改變嗎?
collected_list = list(map(float, collected_list))
print(collected_list)
#print(aa)
結果
TypeError: float() argument must be a string or a number, not 'list'
collected_list = [
[('0.017', '0.107'), ('0.018', '0.115'), ('0.019', '0.113'), ('0.02', '0.109')],
[('0.067', '0.218'), ('0.068', '0.253'), ('0.069', '0.234'), ('0.07', '0.182')]
]
collected_list2 = [ [(float(x), float(y)) for (x,y) in elems] for elems in collected_list]
print(collected_list2)
[[(0.017, 0.107), (0.018, 0.115), (0.019, 0.113), (0.02, 0.109)], [(0.067, 0.218), (0.068, 0.253), (0.069, 0.234), (0.07, 0.182)]]