Can you help me to modify my list? I have a list which consists of three coordinates X Y Z. I need to produce a string with the X Y coordinates delimited by a comma and each coordinate delimited by a newline.
xyz = ['55.548745 35.547852 5.545', '57.85425 37.524852 7.545', '57.214445 38.587852 6.745']
Result should look like this:
xy = "55.548745,35.547852
57.854258,37.524852
57.214445,38.587852"
How can this be done? Thank you in advance for your help.
You can use:
xy = '\n'.join([','.join(coord.split(' ')[0:2]) for coord in xyz])
This iterates through every xyz coordinate, splits them by space, joins the first two coordinates with a comma and produces a list. It then joins the list by newlines, creating the desired result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With