# Buggy code
def converge_file_system(self, name, tags, targets):
    """
    Change attributes (mount targets and tags) of filesystem by name
    """
    result = False
    fs_id = self.get_file_system_id(name)

    if tags is not None:
        tags_to_create, _, tags_to_delete = dict_diff(
            self.get_tags(FileSystemId=fs_id), tags
        )

        if tags_to_delete:
            self.connection.delete_tags(
                FileSystemId=fs_id, TagKeys=[item[0] for item in tags_to_delete]
            )
            result = True

        if tags_to_create:
            self.connection.create_tags(
                FileSystemId=fs_id,
                Tags=[{"Key": item[0], "Value": item[1]} for item in tags_to_create],
            )
            result = True

    if targets is not None:
        incomplete_states = [self.STATE_CREATING, self.STATE_DELETING]
        wait_for(
            lambda: len(self.get_mount_targets_in_state(fs_id, incomplete_states)), 0
        )

        index_by_subnet_id = lambda items: dict(
            (item["SubnetId"], item) for item in items
        )

        current_targets = index_by_subnet_id(self.get_mount_targets(FileSystemId=fs_id))
        targets = index_by_subnet_id(targets)

        targets_to_create, intersection, targets_to_delete = dict_diff(
            current_targets, targets, True
        )

        """ To modify mount target it should be deleted and created again """
        changed = filter(
            lambda sid: not targets_equal(
                ["SubnetId", "IpAddress", "NetworkInterfaceId"],
                current_targets[sid],
                targets[sid],
            ),
            intersection,
        )
        targets_to_delete = list(targets_to_delete) + changed
        targets_to_create = list(targets_to_create) + changed

        if targets_to_delete:
            for sid in targets_to_delete:
                self.connection.delete_mount_target(
                    MountTargetId=current_targets[sid]["MountTargetId"]
                )
            wait_for(
                lambda: len(self.get_mount_targets_in_state(fs_id, incomplete_states)),
                0,
            )
            result = True

        if targets_to_create:
            for sid in targets_to_create:
                self.connection.create_mount_target(FileSystemId=fs_id, **targets[sid])
            wait_for(
                lambda: len(self.get_mount_targets_in_state(fs_id, incomplete_states)),
                0,
                self.wait_timeout,
            )
            result = True

        security_groups_to_update = filter(
            lambda sid: "SecurityGroups" in targets[sid]
            and current_targets[sid]["SecurityGroups"]
            != targets[sid]["SecurityGroups"],
            intersection,
        )

        if security_groups_to_update:
            for sid in security_groups_to_update:
                self.connection.modify_mount_target_security_groups(
                    MountTargetId=current_targets[sid]["MountTargetId"],
                    SecurityGroups=targets[sid]["SecurityGroups"],
                )
            result = True

    return result


# Traceback (TypeError)
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
values = [1,2,3,4,5,6,7,8,9]
gt = lambda x: x > 5
results = filter(gt, values)
type(values)
<class 'list'>
type(results)
<class 'filter'>
values + results
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "filter") to list

# Fixed code
def converge_file_system(self, name, tags, targets):
    """
    Change attributes (mount targets and tags) of filesystem by name
    """
    result = False
    fs_id = self.get_file_system_id(name)

    if tags is not None:
        tags_to_create, _, tags_to_delete = dict_diff(
            self.get_tags(FileSystemId=fs_id), tags
        )

        if tags_to_delete:
            self.connection.delete_tags(
                FileSystemId=fs_id, TagKeys=[item[0] for item in tags_to_delete]
            )
            result = True

        if tags_to_create:
            self.connection.create_tags(
                FileSystemId=fs_id,
                Tags=[{"Key": item[0], "Value": item[1]} for item in tags_to_create],
            )
            result = True

    if targets is not None:
        incomplete_states = [self.STATE_CREATING, self.STATE_DELETING]
        wait_for(
            lambda: len(self.get_mount_targets_in_state(fs_id, incomplete_states)), 0
        )

        index_by_subnet_id = lambda items: dict(
            (item["SubnetId"], item) for item in items
        )

        current_targets = index_by_subnet_id(self.get_mount_targets(FileSystemId=fs_id))
        targets = index_by_subnet_id(targets)

        targets_to_create, intersection, targets_to_delete = dict_diff(
            current_targets, targets, True
        )

        # To modify mount target it should be deleted and created again
        changed = [
            sid
            for sid in intersection
            if not targets_equal(
                ["SubnetId", "IpAddress", "NetworkInterfaceId"],
                current_targets[sid],
                targets[sid],
            )
        ]
        targets_to_delete = list(targets_to_delete) + changed
        targets_to_create = list(targets_to_create) + changed

        if targets_to_delete:
            for sid in targets_to_delete:
                self.connection.delete_mount_target(
                    MountTargetId=current_targets[sid]["MountTargetId"]
                )
            wait_for(
                lambda: len(self.get_mount_targets_in_state(fs_id, incomplete_states)),
                0,
            )
            result = True

        if targets_to_create:
            for sid in targets_to_create:
                self.connection.create_mount_target(FileSystemId=fs_id, **targets[sid])
            wait_for(
                lambda: len(self.get_mount_targets_in_state(fs_id, incomplete_states)),
                0,
                self.wait_timeout,
            )
            result = True

        # If no security groups were passed into the module, then do not change it.
        security_groups_to_update = [
            sid
            for sid in intersection
            if "SecurityGroups" in targets[sid]
            and current_targets[sid]["SecurityGroups"] != targets[sid]["SecurityGroups"]
        ]

        if security_groups_to_update:
            for sid in security_groups_to_update:
                self.connection.modify_mount_target_security_groups(
                    MountTargetId=current_targets[sid]["MountTargetId"],
                    SecurityGroups=targets[sid].get("SecurityGroups", None),
                )
            result = True

    return result