<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_images(prefix, images, tag=None, commit_range=None, push=False, chart_version=None):
 """Build a collection of docker images Args: prefix (str):
 the prefix to add to images images (dict):
 dict of image-specs from chartpress.yml tag (str):
 Specific tag to use instead of the last modified commit. If unspecified the tag for each image will be the hash of the last commit to modify the image's files. commit_range (str):
 The range of commits to consider, e.g. for building in CI. If an image hasn't changed in the given range, it will not be rebuilt. push (bool):
 Whether to push the resulting images (default: False). chart_version (str):
 The chart version, included as a prefix on image tags if `tag` is not specified. """

    value_modifications = {}
    for name, options in images.items():
        image_path = options.get('contextPath', os.path.join('images', name))
        image_tag = tag
        # include chartpress.yaml itself as it can contain build args and
        # similar that influence the image that would be built
        paths = list(options.get('paths', [])) + [image_path, 'chartpress.yaml']
        last_commit = last_modified_commit(*paths)
        if tag is None:
            if chart_version:
                image_tag = "{}-{}".format(chart_version, last_commit)
            else:
                image_tag = last_commit
        image_name = prefix + name
        image_spec = '{}:{}'.format(image_name, image_tag)

        value_modifications[options['valuesPath']] = {
            'repository': image_name,
            'tag': SingleQuotedScalarString(image_tag),
        }

        template_namespace = {
            'LAST_COMMIT': last_commit,
            'TAG': image_tag,
        }

        if tag or image_needs_building(image_spec):
            build_args = render_build_args(options, template_namespace)
            build_image(image_path, image_spec, build_args, options.get('dockerfilePath'))
        else:
            print(f"Skipping build for {image_spec}, it already exists")

        if push:
            if tag or image_needs_pushing(image_spec):
                check_call([
                    'docker', 'push', image_spec
                ])
            else:
                print(f"Skipping push for {image_spec}, already on registry")
    return value_modifications