diff --git a/pixelocr/page.py b/pixelocr/page.py index e7b7fa1..1ec8537 100644 --- a/pixelocr/page.py +++ b/pixelocr/page.py @@ -146,8 +146,9 @@ class Line(PageObject): if glyph.is_body(): continue neighbours = neighbourhood(glyphs, i, 5) - body = max(neighbours, key=lambda neighbour: neighbour.detect_diacritic(glyph)) - if body.detect_diacritic(glyph): + possible_bodies = [body for body in neighbours if body.detect_diacritic(glyph)] + if possible_bodies: + body = possible_bodies[0] diacritics[body].append(glyph) bodies[glyph].append(body) return bodies, diacritics