human
Complete this python program:
def apply_natural_sort(collection, key=None):
assistant
#Here is the Python program you requested.

    """Applies a natural sort (http://rosettacode.org/wiki/Natural_sorting) to a list or dictionary
    Dictionary types require a sort key to be specified
    """
    to_digit = (lambda i: (int(i) if i.isdigit() else i))
    def tokenize_and_convert(item, key=None):
        if key:
            item = item[key]
        return [to_digit(c) for c in re.split('([0-9]+)', item)]
    return sorted(collection, key=(lambda i: tokenize_and_convert(i, key=key)))