import string
import itertools


def standardize_col(col: str) -> str:
    """Standardize a column for Snowflake table.

    (1) Replaces spaces with underscores, trims leading & trailing
        underscores, forces upper-case
    (2) Replaces special characters with underscores
    (3) Reduces repeated special characters

    Args:
        col: A single string value of a column name
    Returns:
        A string that has been re-formatted/standardized for Snowflake
        standards

    """
    col = ((col.replace(' ', '_')).strip('_')).upper()  # 1

    invalid_punct = [punct for punct in string.punctuation if
                     punct != '_']  # 2
    repl_invalid_punct = str.maketrans(''.join(invalid_punct),
                                       '_' * len(invalid_punct))
    col = ''.join(col.translate(repl_invalid_punct))

    new_chars = []  # 3

    for k, v in itertools.groupby(col):
        if k in string.punctuation or k in string.whitespace:
            new_chars.append(k)

        else:
            v_list = list(v)

            new_chars.append(''.join(v_list))

    col = ''.join(new_chars)

    return col