def image_from_name(name, images):

    """Return an image from a list of images.  If the name is an exact
    match, return the last exactly matching image.  Otherwise, sort
    images by 'natural' order, using decorate-sort-undecorate, and
    return the largest.

    see:
    http://code.activestate.com/recipes/285264-natural-string-sorting/
    """

    prefixed_images = [i for i in images if i.name.startswith(name)]

    if name in [i.name for i in prefixed_images]:
        return [i for i in prefixed_images if i.name == name][-1]

    decorated = sorted(
        [(int(re.search('\d+', i.name).group(0)), i) for i in prefixed_images])
    return [i[1] for i in decorated][-1]
Return an image from a list of images.  If the name is an exact
    match, return the last exactly matching image.  Otherwise, sort
    images by 'natural' order, using decorate-sort-undecorate, and
    return the largest.

    see:
    http://code.activestate.com/recipes/285264-natural-string-sorting/