ternary search tree impl in python