Initializes trees package of arandomness

Copyright: Initializes trees package of arandomness Copyright (C) 2017 Alex Hyer

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <>.


The argparse subpackage of arandomness contains scripts and classes relating to trees.

OmniTree (Deprecated)

OmniTree is a class for creating a tree where each node can contain multiple children and multiple parents. I began writing this class because I could not find an extant tree library that supported this many-to-many paradigm. While binary and/or hierarchical tree with only a single parent are common, see anytree, trees like OmniTree are not. After a lot of R&D, I realized that these is such a structure, a graph. Basically, many-to-many trees don’t exist because they cannot by definition. Thus, OmniTree is pointless as there are already amazing libraries for manipulating and managing graphs, such as NetworkX. As such, OmniTree is deprecated and is only included for archival purposes.

API Documentation

class arandomness.trees.OmniTree(label=None, children=None, parents=None)[source]

A many-to-many tree for organizing and manipulating hierarchical data


unicode – optional, arbitrary name for node

__init__(label=None, children=None, parents=None)[source]

Initialize node and inform connected nodes


list of weak references to the object (if defined)


Adds new children nodes after filtering for duplicates

Parameters:children (list) – list of OmniTree nodes to add as children

Adds new parent nodes after filtering for duplicates

Parameters:parents (list) – list of OmniTree nodes to add as parents
find_branches(labels=False, unique=False)[source]

Recursively constructs a list of pointers of the tree’s structure

  • labels (bool) – If True, returned lists consist of node labels. If False (default), lists consist of node pointers. This option is mostly intended for debugging purposes.
  • unique (bool) – If True, return lists of all unique, linear branches of the tree. More accurately, it returns a list of lists where each list contains a single, unique, linear path from the calling node to the tree’s leaf nodes. If False (default), a highly-nested list is returned where each nested list represents a branch point in the tree. See Examples for more.


>>> from arandomness.trees import OmniTree
>>> a = OmniTree(label='a')
>>> b = OmniTree(label='b', parents=[a])
>>> c = OmniTree(label='c', parents=[b])
>>> d = OmniTree(label='d', parents=[b])
>>> e = OmniTree(label='e', parents=[c, d])
>>> a.find_branches(labels=True)
['a', ['b', ['c', ['e']], ['d', ['e']]]]
>>> a.find_branches(labels=True, unique=True)
[['a', 'b', 'c', 'e'], ['a', 'b', 'd', 'e']]

Crappy function that finds a single loop in the tree