def prune(self):
    "Returns a pruned tensor product of observables by removing :class:`~.Identity` instances from\n        the observables building up the :class:`~.Tensor`.\n\n        The ``return_type`` attribute is preserved while pruning.\n\n        If the tensor product only contains one observable, then this observable instance is\n        returned.\n\n        Note that, as a result, this method can return observables that are not a :class:`~.Tensor`\n        instance.\n\n        **Example:**\n\n        Pruning that returns a :class:`~.Tensor`:\n\n        >>> O = qml.PauliZ(0) @ qml.Identity(1) @ qml.PauliZ(2)\n        >>> O.prune()\n        <pennylane.operation.Tensor at 0x7fc1642d1590\n        >>> [(o.name, o.wires) for o in O.prune().obs]\n        [('PauliZ', [0]), ('PauliZ', [2])]\n\n        Pruning that returns a single observable:\n\n        >>> O = qml.PauliZ(0) @ qml.Identity(1)\n        >>> O_pruned = O.prune()\n        >>> (O_pruned.name, O_pruned.wires)\n        ('PauliZ', [0])\n\n        Returns:\n            ~.Observable: the pruned tensor product of observables\n        "
    if (len(self.non_identity_obs) == 0):
        obs = qml.Identity(self.wires[0])
    elif (len(self.non_identity_obs) == 1):
        obs = self.non_identity_obs[0]
    else:
        obs = Tensor(*self.non_identity_obs)
    obs.return_type = self.return_type
    return obs
Returns a pruned tensor product of observables by removing :class:`~.Identity` instances from
the observables building up the :class:`~.Tensor`.

The ``return_type`` attribute is preserved while pruning.

If the tensor product only contains one observable, then this observable instance is
returned.

Note that, as a result, this method can return observables that are not a :class:`~.Tensor`
instance.

**Example:**

Pruning that returns a :class:`~.Tensor`:

>>> O = qml.PauliZ(0) @ qml.Identity(1) @ qml.PauliZ(2)
>>> O.prune()
<pennylane.operation.Tensor at 0x7fc1642d1590
>>> [(o.name, o.wires) for o in O.prune().obs]
[('PauliZ', [0]), ('PauliZ', [2])]

Pruning that returns a single observable:

>>> O = qml.PauliZ(0) @ qml.Identity(1)
>>> O_pruned = O.prune()
>>> (O_pruned.name, O_pruned.wires)
('PauliZ', [0])

Returns:
    ~.Observable: the pruned tensor product of observables
def prune(self):
    "Returns a pruned tensor product of observables by removing :class:`~.Identity` instances from\n        the observables building up the :class:`~.Tensor`.\n\n        The ``return_type`` attribute is preserved while pruning.\n\n        If the tensor product only contains one observable, then this observable instance is\n        returned.\n\n        Note that, as a result, this method can return observables that are not a :class:`~.Tensor`\n        instance.\n\n        **Example:**\n\n        Pruning that returns a :class:`~.Tensor`:\n\n        >>> O = qml.PauliZ(0) @ qml.Identity(1) @ qml.PauliZ(2)\n        >>> O.prune()\n        <pennylane.operation.Tensor at 0x7fc1642d1590\n        >>> [(o.name, o.wires) for o in O.prune().obs]\n        [('PauliZ', [0]), ('PauliZ', [2])]\n\n        Pruning that returns a single observable:\n\n        >>> O = qml.PauliZ(0) @ qml.Identity(1)\n        >>> O_pruned = O.prune()\n        >>> (O_pruned.name, O_pruned.wires)\n        ('PauliZ', [0])\n\n        Returns:\n            ~.Observable: the pruned tensor product of observables\n        "
    if (len(self.non_identity_obs) == 0):
        obs = qml.Identity(self.wires[0])
    elif (len(self.non_identity_obs) == 1):
        obs = self.non_identity_obs[0]
    else:
        obs = Tensor(*self.non_identity_obs)
    obs.return_type = self.return_type
    return obs