0
Complete the code
Hello please I’d like help to write a py code For a function to print out a list of lists in table for so that each colum on the table represents items from each list in the lists? The list of lists to be printed is Tabledata https://code.sololearn.com/ccfYTQ4vROS4/?ref=app
7 ответов
+ 2
Try to add this in your code. Still not sure whether if this is what you after though
shortest = len(min(tableData, key = len))
rows = len(tableData)
for r in range(rows):
for c in range(shortest):
print(tableData [r] [c], end = " | ")
print()
Nwanakwoakwo Wid'obiagu
I have updated the answer. This code output is pretty close to what you described.
(Edited)
+ 2
Nwanakwoakwo Wid'obiagu
Sorry, it's my bad,
Try this maybe better ...
shortest = len(min(tableData, key = len))
rows = len(tableData)
for r in range(shortest):
for c in range(rows):
print(tableData [c] [r], end = " | ")
print()
Output:
kenth | james | snoodog |
rys | jon | emeenem |
apples | kandell | kanyewest |
oranges | sheldon | jayz |
But you said the second row should be like this:
rys | sheldon | eminem |
Though to achieve that the selected column from a row will be different (random?). I don't know how to achieve that.
Where did you get this problem? I saw a question in StackOverflow with almost identical list.
+ 1
I'm having difficulty trying to understand what you want with the code. Can you give a little example and desired output as an illustration? maybe I can help, but no promises : )
+ 1
i would like to print all the items in a table format so that each list has a seperate collum
+ 1
so i want it to print :
kenth james snoop
rys sheldon eminem.... etc
Ipang i tried adding your code but it printed each list on a seperate line. what i want is for the words to be printed like in the example on this coment
+ 1
thank you Ipang
0
You're welcome Nwanakwoakwo Wid'obiagu 👌