Python tree implementation