Aug-09-2021, 07:53 AM
Aug-09-2021, 07:58 AM
In what? Console program? Spreadsheet? Web page?
Aug-09-2021, 08:25 AM
(Aug-09-2021, 07:58 AM)deanhystad Wrote: [ -> ]In what? Console program? Spreadsheet? Web page?Sorry, in Python.
Aug-09-2021, 08:42 AM
number = 2 print(f'number is {number:02}')
Output:number is 02
Aug-09-2021, 08:48 AM
(Aug-09-2021, 08:42 AM)Yoriz Wrote: [ -> ]Thanks.number = 2 print(f'number is {number:02}')
Output:number is 02
My apology for not being clear.
I meant from printing the numbers in lists within a list (sorry I do not know how to express that). Eg
[[1 2 3],[11 22 33],[1 32 6]] to be printed as
[[ 1 2 3], [ 11 22 33], [ 1 32 6]]
As format 3 digits (not 2 digits, realised I need a space in between the numbers).
Thanks.
Aug-09-2021, 11:24 AM
(Aug-09-2021, 08:48 AM)plumberpy Wrote: [ -> ][[1 2 3],[11 22 33],[1 32 6]] to be printed aslist is a internal structure,when want display in output is common to take values of list and format it(without []).
[[ 1 2 3], [ 11 22 33], [ 1 32 6]]
lst = [[1, 2, 3], [11, 22, 33], [1, 32, 6]] for inner in lst: print(' | '.join((f"{word:^2}" for word in inner)))
Output:1 | 2 | 3
11 | 22 | 33
1 | 32 | 6
Tabulate can easily give fancier output.from tabulate import tabulate lst = [[1, 2, 3], [11, 22, 33], [1, 32, 6]] print(tabulate(lst)) print(tabulate(lst, tablefmt="fancy_grid")) print(tabulate(lst, tablefmt="github"))
Output:-- -- --
1 2 3
11 22 33
1 32 6
-- -- --
╒════╤════╤════╕
│ 1 │ 2 │ 3 │
├────┼────┼────┤
│ 11 │ 22 │ 33 │
├────┼────┼────┤
│ 1 │ 32 │ 6 │
╘════╧════╧════╛
|----|----|----|
| 1 | 2 | 3 |
| 11 | 22 | 33 |
| 1 | 32 | 6 |
Aug-09-2021, 02:16 PM
Beautiful!
I was also looking for the grids.
Many many thanks!
I was also looking for the grids.
Many many thanks!