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

21st Dec 2019, 12:09 PM
Nwanakwoakwo Wid'obiagu (kenneth Anyanwu)
Nwanakwoakwo Wid'obiagu (kenneth Anyanwu) - avatar
7 Answers
+ 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)
22nd Dec 2019, 6:13 AM
Ipang
+ 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.
23rd Dec 2019, 7:24 AM
Ipang
+ 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 : )
21st Dec 2019, 2:41 PM
Ipang
+ 1
i would like to print all the items in a table format so that each list has a seperate collum
21st Dec 2019, 11:28 PM
Nwanakwoakwo Wid'obiagu (kenneth Anyanwu)
Nwanakwoakwo Wid'obiagu (kenneth Anyanwu) - avatar
+ 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
22nd Dec 2019, 7:53 AM
Nwanakwoakwo Wid'obiagu (kenneth Anyanwu)
Nwanakwoakwo Wid'obiagu (kenneth Anyanwu) - avatar
+ 1
thank you Ipang
23rd Dec 2019, 7:31 AM
Nwanakwoakwo Wid'obiagu (kenneth Anyanwu)
Nwanakwoakwo Wid'obiagu (kenneth Anyanwu) - avatar
0
You're welcome Nwanakwoakwo Wid'obiagu 👌
23rd Dec 2019, 8:13 AM
Ipang