How to modify my table?

Hello,

i discovered a table i managed to implement it! It works, BUT how to “transpose” my elements.


here is my code so far:


table = ([vals, boxes, types, levelsName, links])


# Sorting and displaying the table
table = sorted(table, key=lambda x: x[1])
out.print_table(table, ["Versatz","Höhe Öffnung","Typ", "Ebene", "Element"])

each item has to be a line and Parameter Values a column.

KR

Andreas

Hi @andreasd811,

I’m not sure what you’re asking here, are you trying to transpose a list of lists? stackoverflow got you covered.

1 Like

@sanzoghenzo ,

thats what i looking for, i think the lamda Expression has to change


table = ([vals, boxes, types, levelsName, links])


# 4️⃣ Sorting and displaying the table

table = map(sorted(table, key=lambda x: x[1]))
# table = list(map(list, zip(table)))
out.print_table(table, ["Versatz","Höhe Öffnung","Typ", "Ebene", "Element"])

You just have to transopose before the sorting, if sorting by value is what you’re after. Doing this, you can drop the map that encloses the sorted function.

You forgot to use the * before the table in the zip function. This is not a typo in stackoverflow answer, is the special character that tells python to unpack the list into the separate items.

Now that I think of, you could just change the table initialization with

table = list(map(list, zip(vals, boxes, types, levelsName, links)))

Or, using list comprehension:

table=[list(record) for record in zip(vals, boxes, types, levelsName, links)]
2 Likes

@sanzoghenzo ,

thank you that was the key.

KR

Andreas

1 Like