<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def set_all(self, path, body):
        "Replaces the hosts list with the provided input"
        # Do some error checking
        if not isinstance(body, dict):
            raise HttpBadRequest("body_not_a_dict")
        for hostname, details in body.items():
            error = self.host_errors(hostname, details)
            if error:
                raise HttpBadRequest("%s:%s" % (hostname, error))
        # Replace
        old_hostnames = set(self.balancer.hosts.keys())
        new_hostnames = set(body.keys())
        self.balancer.hosts = body
        # Clean up stats dict
        for hostname in new_hostnames - old_hostnames:
            self.balancer.stats[hostname] = {}
        for hostname in old_hostnames - new_hostnames:
            try:
                del self.balancer.stats[hostname]
            except KeyError:
                pass
        return {"ok": True}