def label_key(label, padding=5):
    """Returns a padded key from a label representing a milestone number.
    All parts of a label that are numbers are padded so that alphabetical
    sorting can work as expected (e.g., '2.0' < '11.0'). 

    For example, this function will return 'v00001.00022e-00123b' if label =
    'v1.22e-123b'.

    :param label: the milestone label
    :param padding: the maximum number of characters for each numeric part.
           Default=5
    :return: a key that can be used in alphabetical sorting
    """
    key = prefix = ''
    components = []
    in_prefix = True
    current_number = current_suffix = ''
    for c in label:
        if not c.isdigit():
            if in_prefix:
                prefix += c
            else:
                current_suffix += c
        else:
            if in_prefix:
                in_prefix = False
            if current_suffix != '':
                components.append((current_number, current_suffix))
                current_number = current_suffix = ''
            current_number += c
    if not in_prefix and current_number != '':
        components.append((current_number, current_suffix))
    key = prefix
    for component in components:
        key += component[0].rjust(padding, '0') + component[1]
    return key
