From 33a95555dca3f719bd5ad1b1bdc7042427e0e11e Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 13 Sep 2021 22:36:44 +0100 Subject: [PATCH] Use list comprehension to initialize paths `[[]] * length` creates an array of the correct length, but where every entry is an alias to the same inner array. Pushing to any of the arrays was behaving as if we were pushing to all of them, instead of updating independent paths. --- orchard_merkle_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchard_merkle_tree.py b/orchard_merkle_tree.py index 7f21d05..2cc30b7 100644 --- a/orchard_merkle_tree.py +++ b/orchard_merkle_tree.py @@ -60,7 +60,7 @@ def main(): # Derive path for each leaf in a tree of depth 4. def get_paths_and_root(leaves): assert(len(leaves) == (1 << SMALL_DEPTH)) - paths = [[]] * (1 << SMALL_DEPTH) + paths = [[] for _ in range(1 << SMALL_DEPTH)] # At layer 0, we want: # - leaf 0: sibling 1