<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _tot_services_by_state(self, state=None, state_type=None):
 """Generic function to get the number of services in the specified state :param state: state to filter on :type state: str :param state_type: state type to filter on (HARD, SOFT) :type state_type: str :return: number of host in state *state* :rtype: int TODO: Should be moved """

        if state is None and state_type is None:
            return len(self.services)
        if state_type:
            return sum(1 for s in self.services if s.state == state and s.state_type == state_type)
        return sum(1 for s in self.services if s.state == state)