I am currently working with the Node_Coords_Section of the berlin52.tsp file
This gives the following output:
JavaScript
x
2
1
{1: [565.0, 575.0], 2: [25.0, 185.0], 3: [345.0, 750.0], 4: [945.0, 685.0], 5: [845.0, 655.0], .}
2
In order to be able to use satsp, I need to change the latter in this format:
JavaScript
1
2
1
[[1, 566.0, 575.0], [2, 25.0, 185.0], [3, 345.0, 750.0], ..]
2
What should I do to get it in this format?
Advertisement
Answer
Use
lst = [[x,*y] for x, y in dic.items()]
Here is the full code:
JavaScript
1
6
1
dic = {1: [565.0, 575.0], 2: [25.0, 185.0], 3: [345.0, 750.0], 4: [945.0, 685.0], 5: [845.0, 655.0]}
2
3
lst = [[x,*y] for x, y in dic.items()]
4
5
print(lst)
6
OP: [[1, 565.0, 575.0], [2, 25.0, 185.0], [3, 345.0, 750.0], [4, 945.0, 685.0], [5, 845.0, 655.0]]