Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sorting multiple lists to get a single organised list

I have multiple lists with coordinates:

x = [2423, 2342, 4432]
 
y = [532, 5432, 5432] 

w = [7456, 256, 5645] 

h = [2345, 6543, 8764] 

I want to concatenate these lists so that the position of an item would correspond with the position of other items in a single list. You can think of it as a dataset for every item in x, y, w, h with the same position in the same list

for example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Boxes = [
[x[0],y[0],w[0],h[0]],
[x[1],y[1],w[1],h[1]],
[x[2],y[2],w[2],h[2]],
]

Of course I would not write manually the position of an element for every list, but this shows what I want to achieve.
Any help would be appreciated

>Solution :

After setting the coordinates dynamically, you can append them into the boxes one by one using the for loop with the length of the x. Please note length of all arrays should be the same.

x = [2423, 2342, 4432]
y = [532, 5432, 5432] 
w = [7456, 256, 5645] 
h = [2345, 6543, 8764] 

Boxes = []

for i in range(len(x)):
    Boxes.append([x[i], y[i], w[i], h[i]])

After this Boxes value would be equal to that:

[[2423, 532, 7456, 2345], [2342, 5432, 256, 6543], [4432, 5432, 5645, 8764]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading