Reputation: 23
Trying to create a ticket for a game of Housie and want the output to be as below from a list of numbers
input_list = [[14, 15, 17, 26, 31], [36, 41, 42, 43, 62], [67, 75, 85, 87, 92]]
Output:
| 14 | 15 | 17 | 26 | 31 |
| 36 | 41 | 42 | 43 | 62 |
| 67 | 75 | 85 | 87 | 92 |
Upvotes: 2
Views: 37
Reputation: 3177
for e in input_list:
print('|', '|'.join(map(str, e)), '|', sep='')
print() # remove this if you don't need an empty line after each row
Above code iterates through all elements in the list and formats each one individually. First, one |
is printed. After that, elements of the upper level loop's element are joined in the strings ('|'.join
means that |
will be used to separate elements). And for the end, another |
is printed.
Upvotes: 2