You can download this code by clicking the button below.
This code is now available for download.
This function creates a table to display people's names, ages, and locations. It uses the Table class from the Rich library to construct and display the table.
Technology Stack : Rich
Code Type : Function
Code Difficulty : Intermediate
def rich_table_example(data):
from rich.table import Table
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Name", justify="left")
table.add_column("Age", justify="right")
table.add_column("Location", justify="left")
for row in data:
table.add_row(row[0], str(row[1]), row[2])
print(table)
# Usage example
data = [
["Alice", 30, "New York"],
["Bob", 25, "Los Angeles"],
["Charlie", 35, "Chicago"]
]
rich_table_example(data)