Created
April 15, 2025 01:49
-
-
Save yeiichi/bb02a914909ca3a5edffc0506f947c02 to your computer and use it in GitHub Desktop.
Make a labeled matrix with specified rows, columns, and prefix for labels.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from argparse import ArgumentParser | |
from pprint import pprint | |
from typing import List | |
COLOR_Y = "\033[93m" | |
COLOR_0 = "\033[0m" | |
def make_labeled_matrix(num_rows: int, num_cols: int, prefix: str = 'a') -> List[List[str]]: | |
""" | |
Make a labeled matrix with specified rows, columns, and prefix for labels. | |
""" | |
return [ | |
[f'{prefix}_{row}{col}' for col in range(1, num_cols + 1)] | |
for row in range(1, num_rows + 1) | |
] | |
def cli_runner(): | |
"""Entry point for command-line usage.""" | |
parser = ArgumentParser(description="Generate a labeled matrix of strings.") | |
parser.add_argument("rows", type=int, help="Number of rows") | |
parser.add_argument("cols", type=int, help="Number of columns") | |
parser.add_argument("--prefix", type=str, default='a', help="Prefix for labels (default: 'a')") | |
args = parser.parse_args() | |
matrix = make_labeled_matrix(args.rows, args.cols, args.prefix) | |
print(f"{COLOR_Y} Labeled Matrix: {COLOR_0}") | |
pprint(matrix) | |
if __name__ == '__main__': | |
cli_runner() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment