'convert List of List to list float

I have a list of list of coordinate with data type of float for example something like this

[[106.4372634887695, -6.3303128514375], [106.4372634887695, -6.3299716218919], [106.4376068115234, -6.3299716218919]]

and I want to convert it so the inside bracket would be gone and replaced only by comma. and the comma inside the deepest bracket would be replaced too by space

and the final format would be something like

((106.4372634887695 -6.3303128514375, 106.4372634887695 -6.3299716218919, 106.4376068115234 -6.3299716218919))

Is there a good way to solve this?

I tried to use map and join but i didn't succeeded



Solution 1:[1]

The format you want is not the representation of any type which exists in Python. If you want it as a string, then, turn to string processing:

pairs = [[106.4372634887695, -6.3303128514375], [106.4372634887695, -6.3299716218919], [106.4376068115234, -6.3299716218919]]

stringified = ', '.join(' '.join(map(str,pair)) for pair in pairs)

parenthesized = f'(({stringified}))'

Solution 2:[2]

You can flatten your array by using:

flatten = [elm for bracket in data for elm in bracket]

It's like:

arr = []
for bracket in data:
    for x in bracket:
        arr.append(x) #or arr += [x]

If you just want to sum brackets, do:

final = [a + b for a,b in arr]#b is -|b|, it's negative, then a+b is the same as 106.xxx - 6.xxx

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Unrelated String
Solution 2 marc_s