Python Forum
Space between list and column alignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Space between list and column alignment
#8
List is a data structure(internal use) and not meant to view like this,as that make no senseπŸ¦„
For view take elements out data structure,then can figure a different way to view it.
>>> list_a = [1,2,3,4,5]
>>> list_b = ['d','h','f','s','g']
>>> lst = []
>>> lst.append([str(i) for i in list_a])
>>> lst.append(list_b)
>>> 
>>> lst
[['1', '2', '3', '4', '5'], ['d', 'h', 'f', 's', 'g']]
>>> 
>>> for inner in lst:
...     print(' | '.join((f"{word:4}" for word in inner)))
...     
1    | 2    | 3    | 4    | 5   
d    | h    | f    | s    | g 
>>> from tabulate import tabulate
>>> 
>>> print(tabulate(lst, tablefmt="fancy_grid"))
╒═══╀═══╀═══╀═══╀═══╕
β”‚ 1 β”‚ 2 β”‚ 3 β”‚ 4 β”‚ 5 β”‚
β”œβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”Όβ”€β”€β”€β”€
β”‚ d β”‚ h β”‚ f β”‚ s β”‚ g β”‚
β•˜β•β•β•β•§β•β•β•β•§β•β•β•β•§β•β•β•β•§β•β•β•β•›
>>> print(tabulate(lst, tablefmt="pretty"))
+---+---+---+---+---+
| 1 | 2 | 3 | 4 | 5 |
| d | h | f | s | g |
+---+---+---+---+---+
>>> print(tabulate(lst, tablefmt="simple"))
-  -  -  -  -
1  2  3  4  5
d  h  f  s  g
-  -  -  -  -
>>> print(tabulate(lst, tablefmt="youtrack"))
|  1  |  2  |  3  |  4  |  5  |
|  d  |  h  |  f  |  s  |  g  |  
Reply


Messages In This Thread
Space between list and column alignment - by rturus - Mar-09-2021, 11:13 AM
RE: Space between list and column alignment - by snippsat - Mar-15-2021, 08:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python code for alignment and font size 1418 0 389 Jan-14-2024, 03:56 AM
Last Post: 1418
  make all text in Right to left alignment in tkinter widgets jalal0034 1 1,449 Sep-27-2022, 06:42 PM
Last Post: Larz60+
  Right to left alignment in python report using Reportlab jalal0034 1 1,932 Sep-27-2022, 04:25 AM
Last Post: jalal0034
  pandas, tabulate, and alignment menator01 3 7,537 Feb-05-2022, 07:04 AM
Last Post: menator01
  Not able to add extra column to the list in the python shantanu97 2 1,721 Nov-17-2021, 10:14 AM
Last Post: snippsat
  Sort List of Lists by Column Nju 1 13,495 Apr-13-2021, 11:59 PM
Last Post: bowlofred
  from global space to local space Skaperen 4 2,406 Sep-08-2020, 04:59 PM
Last Post: Skaperen
  Get Value from List to Show in DataFrame Column ahmedwaqas92 1 1,961 Jun-22-2020, 08:24 AM
Last Post: ahmedwaqas92
  list comprehension : print column as row pyseeker 4 3,797 Sep-05-2019, 05:40 AM
Last Post: pyseeker
  Inserting a python list into a dataframe column wise mahmoud899 0 4,326 Mar-04-2019, 11:44 PM
Last Post: mahmoud899

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020