🛠️ToolsShed

Acronym Generator

Generate acronyms and abbreviations from phrases. Expand existing acronyms letter by letter.

Preguntas Frecuentes

Implementación de Código

import re

def generate_acronym(text: str, skip_words: list[str] | None = None) -> str:
    """Generate an acronym from a phrase by taking first letters."""
    if skip_words is None:
        skip_words = ["a", "an", "the", "of", "in", "on", "at", "to", "for", "and", "or"]

    words = re.findall(r"[a-zA-Z]+", text)
    acronym_letters = [
        w[0].upper()
        for w in words
        if w.lower() not in skip_words
    ]
    return "".join(acronym_letters)

def generate_acronym_options(text: str) -> dict:
    """Generate multiple acronym variants."""
    words = re.findall(r"[a-zA-Z]+", text)
    skip_words = ["a", "an", "the", "of", "in", "on", "at", "to", "for", "and", "or"]

    all_letters = [w[0].upper() for w in words]
    filtered_letters = [w[0].upper() for w in words if w.lower() not in skip_words]

    return {
        "all_words": "".join(all_letters),
        "skip_common": "".join(filtered_letters),
        "original": text
    }

# Examples
examples = [
    "Application Programming Interface",
    "World Health Organization",
    "Artificial Intelligence",
]
for phrase in examples:
    result = generate_acronym_options(phrase)
    print(f"'{phrase}'")
    print(f"  All words:    {result['all_words']}")
    print(f"  Skip common:  {result['skip_common']}")
    print()

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.