Pretty-print tabular data in Python with extensive formatting options and output format support.
Overall
score
69%
Create a Python program that formats sales data into well-aligned tables with specific column alignment.
Your program should accept sales data (as a list of lists) and column headers, then return a formatted table string with the following alignment:
When formatting this data:
data = [
[101, "Widget A", "Electronics", 45, 2250.50],
[2, "Gadget Premium", "Home", 123, 15372.25],
[3456, "Tool X", "Garden", 8, 159.99]
]
headers = ["Product ID", "Product Name", "Category", "Units Sold", "Revenue"]The formatted table should have Product ID right-aligned, Product Name left-aligned, Category center-aligned, and numeric columns (Units Sold, Revenue) aligned by decimal point.
@test
When formatting this data:
data = [
[500, "Premium Item", "Luxury", 5, 9999.99],
[25, "Budget Item", "Economy", 250, 125.00]
]
headers = ["ID", "Item", "Type", "Qty", "Price"]The table should have all columns right-aligned by default, except the "Item" column which should be left-aligned.
@test
When formatting this financial data:
data = [
["Q1 2024", 125000.5, 98234.125, 26766.375],
["Q2 2024", 142500.0, 105670.0, 36830.0],
["Q3 2024", 98750.25, 82109.5, 16640.75]
]
headers = ["Quarter", "Revenue", "Costs", "Profit"]String columns should be left-aligned while numeric columns should be aligned by decimal point.
@test
@generates
def format_sales_report(data, headers):
"""
Format sales data into an aligned table.
Args:
data: List of lists containing sales records
headers: List of column header strings
Returns:
str: Formatted table with custom column alignments
"""Provides table formatting and alignment capabilities.
Install with Tessl CLI
npx tessl i tessl/pypi-tabulatedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10