<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def list_deployments(self, namespace=None):
 """ List all available deployments. :param namespace: str, if not specified list deployments for all namespaces :return: collection of instances of :class:`conu.backend.k8s.deployment.Deployment` """


        if namespace:
            return [Deployment(name=d.metadata.name,
                               namespace=d.metadata.namespace,
                               labels=d.metadata.labels, selector=d.spec.selector,
                               image_metadata=ImageMetadata(
                                   name=d.spec.template.spec.containers[0].name.split("-", 1)[0]))
                    for d in self.apps_api.list_namespaced_deployment(namespace, watch=False).items]

        return [Deployment(name=d.metadata.name,
                           namespace=d.metadata.namespace,
                           labels=d.metadata.labels, selector=d.spec.selector,
                           image_metadata=ImageMetadata(
                               name=d.spec.template.spec.containers[0].name.split("-", 1)[0]))
                for d in self.apps_api.list_deployment_for_all_namespaces(watch=False).items]