def file_sorting_key(filename):
    """
    Extract a key for a filename sort, putting JPEGs before everything else.
    """
    extension = filename.lower()[filename.rfind('.') + 1:]
    key = 0 if extension in ('jpg', 'jpeg') else 1
    return key, filename
