<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def expectation(self, operator: Union[PauliTerm, PauliSum]):
 """ Compute the expectation of an operator. :param operator: The operator :return: The operator's expectation value """

        if not isinstance(operator, PauliSum):
            operator = PauliSum([operator])

        return sum(_term_expectation(self.wf, term, n_qubits=self.n_qubits) for term in operator)