def split_file_name_for_sort(f):
    """
    Returns tuple of string and integer components for sorting

    For example:

    "cluster_10.txt" -> ("cluster_",10,".txt")
    """
    components = []
    current_component = ''
    component_is_digits = False
    # Loop over characters in the input string
    for c in str(f):
        if current_component:
            # Already building a group of characters
            if (c.isdigit() and not component_is_digits) or \
               (not c.isdigit() and component_is_digits):
                # Next character is a different type from
                # the current group, so the current group
                # is complete
                if component_is_digits:
                    # Convert digits to integer
                    current_component = int(current_component)
                components.append(current_component)
                # Reset for a new group of characters
                current_component = ''
                component_is_digits = False
            else:
                # Next character is same type as current
                # group, just append it
                current_component += c
        if not current_component:
            # Next character starts a new group
            current_component += c
            component_is_digits = c.isdigit()
    # Finished looping, check if there is a final
    # unprocessed character group
    if current_component:
        if component_is_digits:
            # Convert digits to integer
            current_component = int(current_component)
        components.append(current_component)
    # Return the tuple of elements
    return tuple(components)