Simple tree operations in Python