import re


def file_sort_key(file):
    """
    Given a directory with...
    "test1.txt, test2.txt, test10.txt"
    The os.listdir() will return... 
    "test1.txt, test10.txt, test2.txt"
    To make %n work, we need it to return the files in a logical/natural form.
    We use this key to achieve that, while also using the sorted() function.

    Parameters: 
        unsorted_files : list
            A list of unsorted files
    """

    key = re.split(r'(\d+)', file)
    key[1::2] = map(int, key[1::2])
    return key