CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-tabulate

Pretty-print tabular data in Python with extensive formatting options and output format support.

Overall
score

69%

Overview
Eval results
Files

task.mdevals/scenario-4/

Sales Report Formatter

Create a Python program that formats sales data into well-aligned tables with specific column alignment.

Requirements

Your program should accept sales data (as a list of lists) and column headers, then return a formatted table string with the following alignment:

  1. The first column (Product ID) should be right-aligned
  2. The second column (Product Name) should be left-aligned
  3. The third column (Category) should be center-aligned
  4. The remaining numeric columns should be aligned by decimal point

Test Cases

Test case 1: Per-column 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

Test case 2: Global alignment with specific override

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

Test case 3: String and numeric column defaults

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

Implementation

@generates

API

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
    """

Dependencies { .dependencies }

tabulate { .dependency }

Provides table formatting and alignment capabilities.

Install with Tessl CLI

npx tessl i tessl/pypi-tabulate

tile.json