<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def request_leadership(self, opt_count, skip_brokers, skip_partitions):
 """Under-balanced broker requests leadership from current leader, on the pretext that it recursively can maintain its leadership count as optimal. :key_terms: leader-balanced: Count of brokers as leader is at least opt-count Algorithm: ========= Step-1: Broker will request leadership from current-leader of partitions it belongs to. Step-2: Current-leaders will grant their leadership if one of these happens:- a) Either they remain leader-balanced. b) Or they will recursively request leadership from other partitions until they are become leader-balanced. If both of these conditions fail, they will revoke their leadership-grant Step-3: If current-broker becomes leader-balanced it will return otherwise it moves ahead with next partition. """

        # Possible partitions which can grant leadership to broker
        owned_partitions = list(filter(
            lambda p: self is not p.leader and len(p.replicas) > 1,
            self.partitions,
        ))
        for partition in owned_partitions:
            # Partition not available to grant leadership when:
            # 1. Broker is already under leadership change or
            # 2. Partition has already granted leadership before
            if partition.leader in skip_brokers or partition in skip_partitions:
                continue
            # Current broker is granted leadership temporarily
            prev_leader = partition.swap_leader(self)
            # Partition shouldn't be used again
            skip_partitions.append(partition)
            # Continue if prev-leader remains balanced
            # If leadership of prev_leader is to be revoked, it is considered balanced
            if prev_leader.count_preferred_replica() >= opt_count or \
                    prev_leader.revoked_leadership:
                # If current broker is leader-balanced return else
                # request next-partition
                if self.count_preferred_replica() >= opt_count:
                    return
                else:
                    continue
            else:  # prev-leader (broker) became unbalanced
                # Append skip-brokers list so that it is not unbalanced further
                skip_brokers.append(prev_leader)
                # Try recursively arrange leadership for prev-leader
                prev_leader.request_leadership(opt_count, skip_brokers, skip_partitions)
                # If prev-leader couldn't be leader-balanced
                # revert its previous grant to current-broker
                if prev_leader.count_preferred_replica() < opt_count:
                    # Partition can be used again for rebalancing
                    skip_partitions.remove(partition)
                    partition.swap_leader(prev_leader)
                    # Try requesting leadership from next partition
                    continue
                else:
                    # If prev-leader successfully balanced
                    skip_partitions.append(partition)
                    # Removing from skip-broker list, since it can now again be
                    # used for granting leadership for some other partition
                    skip_brokers.remove(prev_leader)
                    if self.count_preferred_replica() >= opt_count:
                        # Return if current-broker is leader-balanced
                        return
                    else:
                        continue