From ce0974617a76ba073797aecb17e4548bfda1534d Mon Sep 17 00:00:00 2001 From: Ilan Schnell Date: Mon, 10 May 2021 21:52:08 -0500 Subject: [PATCH] simplify traverse() in huffman_code() --- bitarray/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitarray/util.py b/bitarray/util.py index 32932d06..746e2c7c 100644 --- a/bitarray/util.py +++ b/bitarray/util.py @@ -379,9 +379,9 @@ def huff_tree(freq_map): result = {} def traverse(nd, prefix=bitarray(0, endian)): - if hasattr(nd, 'symbol'): # leaf + try: # leaf result[nd.symbol] = prefix - else: # parent, so traverse each of the children + except AttributeError: # parent, so traverse each of the children traverse(nd.child[0], prefix + bitarray([0])) traverse(nd.child[1], prefix + bitarray([1]))