What is the most efficient way to get all nodes in a certain depth
tonyliangli opened this issue · 4 comments
tonyliangli commented
Hi,
Thanks for the great lib. I would like to know how to get all nodes in a certain depth. I tried expand_tree with mode width, but i can only get nodes. I have to use level() to check the level. Please tell me if there's a better way. Thanks!
leonardbinet commented
Hi @tonyliangli , can you precise what is the expected output?
Do you want list of nodes at a given depth or do you want a tree truncated at a given depth?
tonyliangli commented
Thanks for the reply, I would like a list of nodes at a given depth. Is expand_tree with filter the only way?
| |
Tony Li
|
|
tonyliangli@163.com
|
On 03/02/2020 14:36, Léonard Binet wrote:
Hi @tonyliangli , can you precise what is the expected output?
Do you want list of nodes at a given depth or do you want a tree truncated at a given depth?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
leonardbinet commented
Sorry for late reply, you can use filter_nodes
method:
depth_2_nodes = list(my_tree.filter_nodes(lambda x: my_tree.depth(x) == 2))
tonyliangli commented
Got it. Thanks a lot.
| |
Tony Li
|
|
tonyliangli@163.com
|
On 03/09/2020 10:37, Léonard Binet wrote:
Sorry for late reply, you can use filter_nodes method:
depth_2_nodes = list(t.filter_nodes(lambda x: t.depth(x) == 2))
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.