I need to build a table with the data like this:
┌────────┬───────────┬────────┐
│ ID │ Name │ Age │
├────────┼───────────┼────────┤
│ 1 │ Jonh │ 35 │
├────────┼───────────┼────────┤
│ 2 │ Joseph │ 40 │
└────────┴───────────┴────────┘
I am not allowed use any Python libraries for that. It has to be done from scratch. I found that there are some box drawing unicode characters that I could use to draw the table(https://en.wikipedia.org/wiki/Box-drawing_character). Ex:
print(u'\u250C') -> will print ─
I am lost on how I should approach this problem. Should I print the data and then draw the table around or should I print the complete boxed row by row. Any help is appreciated.
My work so far:
length_list = [len(element) for row in data for element in row]
column_width = max(length_list)
for row in data:
print(u'\u250C' + (u'\u2500'*column_width*len(data[0])) + u'\u2510')
row = "".join(element.ljust(column_width + 2) for element in row)
print(row)
print(u'\u2514' + (u'\u2500'*column_width*len(data[0])) + u'\u2518')
Gives me this:
┌──────────────────┐
ID Name Age
└──────────────────┘
┌──────────────────┐
1 John 35
└──────────────────┘
┌──────────────────┐
2 Joseph 40
└──────────────────┘