import re


def timedur_standardize(timedur: str) -> str:
    """
    Convert a user-input ambiguous time duration string to standard
    abbreviations, following the rules:
       1. No space.
       2. One letter represents unit.
       3. s,m,h,d,W,M for seconds, minutes, hours, days, weeks and months.

    :param timedur: A user-input ambiguous time duration string,
                    like '1 min', '5days',etc.
    :returns: standardized time duration string.

    """
    timedur_num = re.findall('\d+', timedur)[0]  # find all digits
    timedur_strs = re.findall('[a-zA-Z]', timedur)  # find all letters

    if len(timedur_strs) == 1:
        # If only one letter, lower/upper case "m"/"M" to diff min and month
        timedur_unit = timedur_strs[0].lower()
        if timedur_unit not in ('s', 'm', 'h', 'd', 'w', 'y'):
            raise Exception(
                'Invalid input time duration unit: {}!'.format(timedur))
        if timedur_strs[0] in ('w', 'W', 'M', 'y', 'Y'):  # Upper case for week/month/year
            timedur_unit = timedur_unit.upper()
    else:
        unit_map = {
            'sec': 's',
            'min': 'm',
            'hour': 'h',
            'hr': 'h',
            'day': 'd',
            'wk': 'W',
            'week': 'W',
            'mo': 'M',
            'mon': 'M',
            'yr': 'Y',
            'year': 'Y'
        }
        timedur_unit = ''
        for k in unit_map.keys():
            timedur_strs = re.findall(k, timedur)
            if timedur_strs:
                timedur_unit = unit_map[k]
                break
        if not timedur_unit:
            raise TypeError(
                "Invalid input time duration unit: {}!".format(timedur))
    return timedur_num + timedur_unit