Home > Software engineering >  coverting list of string coordinates into list of lists coordinates without string
coverting list of string coordinates into list of lists coordinates without string

Time:11-17

I have a list of list of strings, but each string a coordinate separated by commas, I want to convert into list of lists of coordinates without string

my_list =['44324,-34244', '44885.1,-33445.6', '45373.1,-32849.8', '45380.1,-32625.6', '44635.7,-32285.6', '44635.7,-32285.6']

I want to convert into

[[44324,-34244], [44885.1,-33445.6], [45373.1,-32849.8], [45380.1,-32625.6], [44635.7,-32285.6], [44635.7,-32285.6]]```

I tried the following but it doesn't work


```coords = [map(float,i.split(",")) for i in my_list]```

print(coords) gives me gives me <map object at 0x7f7a7715d2b0>

CodePudding user response:

Wrap map(...) in list(...) like so:

coords = [list(map(float,i.split(","))) for i in my_list]
  • Related