CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-us

A package for easily working with US and state metadata

Overall
score

88%

Overview
Eval results
Files

task.mdevals/scenario-3/

FIPS Code Validation System

Build a utility that validates and resolves US state FIPS codes from user input.

Requirements

Your system should accept a list of potential FIPS codes (as strings) and return information about their validity and corresponding states.

Core Functionality

Implement a function validate_fips_codes(codes) that:

  • Accepts a list of strings representing potential FIPS codes
  • For each code, determines if it is a valid US state or territory FIPS code
  • Returns a dictionary with the following structure:
    • valid: list of tuples, each containing (fips_code, state_name, state_abbreviation) for valid codes
    • invalid: list of codes that are not valid FIPS codes

Additional Requirements

  • FIPS codes should be validated for both states and territories
  • The function should handle leading zeros (e.g., "01" for Alabama, "06" for California)
  • Invalid codes should be collected and reported
  • State names should be the full official names (e.g., "Alabama", not "AL")

Test Cases

  • Given codes ["01", "06", "24", "99", "invalid"], the function returns valid entries for "01" (Alabama), "06" (California), and "24" (Maryland), and marks "99" and "invalid" as invalid @test

  • Given codes ["78", "72", "00"], the function returns valid entries for "78" (Virgin Islands) and "72" (Puerto Rico), and marks "00" as invalid @test

  • Given an empty list [], the function returns empty lists for both valid and invalid @test

Implementation

@generates

API

def validate_fips_codes(codes):
    """
    Validate a list of FIPS codes and return information about valid states/territories.

    Args:
        codes: List of strings representing potential FIPS codes

    Returns:
        Dictionary with keys:
            - 'valid': List of tuples (fips_code, state_name, abbreviation)
            - 'invalid': List of invalid codes
    """
    pass

Dependencies { .dependencies }

python-us { .dependency }

Provides US state and territory metadata including FIPS code lookup capabilities.

Install with Tessl CLI

npx tessl i tessl/pypi-us

tile.json