•  
  • 1
  •  
1

Разъясните работу python yield примере

Объясните, пожалуйста, доступным языком. Что делает следующий кусок кода?


def node._get_child_candidates(self, distance, min_dist, max_dist):
    if self._leftchild and distance - max_dist < self._median:
        yield self._leftchild
    if self._rightchild and distance + max_dist >= self._median:
        yield self._rightchild

И пример того как вызывается данная функция:


result, candidates = list(), [self]
while candidates:
    node = candidates.pop()
    distance = node._get_dist(obj)
    if distance <= max_dist and distance >= min_dist:
        result.extend(node._values)
        candidates.extend(node._get_child_candidates(distance, min_dist, max_dist))
        return result

Что происходит, когда вызывается метод getchildcandidates? Она возвращает список или единственный элемент? Может использоваться повторно? И для какой версии python характерно объявление метода как: def node._get_child_candidates(self, distance, min_dist, max_dist)

python, yield.
спросил 664 дня назад Аватор пользователя community community
100 2
300
Чтобы написать ответ, вы должны авторизироваться.