0

I have two lists now shown below:

Coord_leaking_pipes_x_coords:  [387.02, 1899.68, 2485.55, 1167.79, 296.91, 937.42, 1293.7, 267.81, 540.25, 1112.86, 1249.76, 1655.71, 2413.3, 2691.82]
Coord_leaking_pipes_y_coords:  [956.05, 803.57, 632.88, 713.02, 1569.97, 1141.56, 960.69, 423.37, 317.17, 345.85, 430.96, 657.27, 397.27, 842.85]

I want to get the new list shown below, it is to put the element in the same position of two lists shown above together to form a list and put those new lists into a big list.

Coord_leaking_pipes_coords; [[387.02,956.05],[1899.68,803.57],[2485.55,632.88],[1167.79,713.02],......,[2691.82,842.85]]

Could you please tell me how can I achieve it?

martineau
  • 119,623
  • 25
  • 170
  • 301
czy
  • 523
  • 2
  • 4
  • 12

2 Answers2

1

Here's one way that uses the built-in zip() function:

x_coords = [387.02, 1899.68, 2485.55, 1167.79, 296.91, 937.42, 1293.7, 267.81, 540.25, 1112.86, 1249.76, 1655.71, 2413.3, 2691.82]
y_coords = [956.05, 803.57, 632.88, 713.02, 1569.97, 1141.56, 960.69, 423.37, 317.17, 345.85, 430.96, 657.27, 397.27, 842.85]

coords = list(list(t) for t in zip(x_coords, y_coords))
martineau
  • 119,623
  • 25
  • 170
  • 301
0

x = [387.02, 1899.68, 2485.55, 1167.79, 296.91, 937.42, 1293.7, 267.81, 540.25, 1112.86, 1249.76, 1655.71, 2413.3, 2691.82]

y = [956.05, 803.57, 632.88, 713.02, 1569.97, 1141.56, 960.69, 423.37, 317.17, 345.85, 430.96, 657.27, 397.27, 842.85]

result = [[x[i],y[i]] for i in range(len(x))]

gesling
  • 67
  • 4
  • FYI: You can use a limited version of markdown to format your questions and answers quite nicely. [Here's some formatting help](https://stackoverflow.com/help/formatting). – martineau Jul 16 '21 at 20:27
  • @rici - thanks for pointing out the mistake in original answer. Edit done. – gesling Jul 16 '21 at 21:08
  • @martineau - thanks for the suggestion. I agree formatting would improve the readability. – gesling Jul 16 '21 at 21:10