Change List format in Python

Advertisements

I have an List like down below

[['-6.167665', '106.904251'], ['-6.167665', '106.904251']]

How to make it like this?

[[-6.167665, 106.904251], [-6.167665, 106.904251]]

Any suggestions how to do it?

>Solution :

You want to use float.

original_list = [['-6.167665', '106.904251'], ['-6.167665', '106.904251']]
print(original_list)

new_list = [[float(i) for i in inner] for inner in original_list]
print(new_list)

Leave a Reply Cancel reply