From 63dd0da97c524f2582aef836eed1fbd090404688 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Wed, 18 Mar 2020 22:36:07 +0100 Subject: [PATCH] Treelib: Add first_brother --- seminar/treelib.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/seminar/treelib.py b/seminar/treelib.py index 946e61fd..8cf01660 100644 --- a/seminar/treelib.py +++ b/seminar/treelib.py @@ -18,13 +18,17 @@ def safe_pred(node): except ObjectDoesNotExist: return None +def first_brother(node): + brother = node + while safe_pred(brother) is not None: + brother = safe_pred(brother) + return brother + # A to samé pro .father_of_first def safe_father_of_first(node): - first_brother = node - while safe_pred(first_brother) is not None: - first_brother = safe_pred(first_brother) + first = first_brother(node) try: - return first_brother.father_of_first + return first.father_of_first except ObjectDoesNotExist: return None