Ternary search tree implementation in python 3 I have implemented a Ternary search tree. It works well. But if you think something needs to be improved, say it. This code was tested in Python 3.7.4.

class Node(object):

    def __init__(self, character):
        self.character = character
        self.leftNode = None
        self.middleNode = None
        self.rightNode = None
        self.value = 0

class TST(object):

    def __init__(self):
        self.rootNode = None

    def put(self,key,value):
        self.rootNode = self.putItem(self.rootNode, key, value, 0)

    def putItem(self, node, key, value, index):

        c = key[index]

        if node == None:
            node = Node(c)

        if c &lt; node.character:
            node.leftNode = self.putItem(node.leftNode, key, value, index)
        elif c &gt; node.character:
            node.rightNode = self.putItem(node.rightNode, key, value, index)
        elif index &lt; len(key) - 1:
            node.middleNode = self.putItem(node.middleNode, key, value, index+1)
        else:
            node.value = value

        return node

    def get(self, key):

        node = self.getItem(self.rootNode, key, 0)

        if node == None:
            return -1

        return node.value

    def getItem(self, node, key, index):

        if node == None:
            return None

        c = key[index]

        if c &lt; node.character:
            return self.getItem(node.leftNode, key, index)
        elif c &gt; node.character:
            return self.getItem(node.rightNode, key, index)
        elif index &lt; len(key) - 1:
            return self.getItem(node.middleNode, key, index+1)
        else:
            return node

if __name__ == "__main__":

    tst = TST()

    tst.put("apple",100)
    tst.put("orange",200)

    print( tst.get("orange") )
Data structure-wise, it seems okay, and does what you're after.

Code-style wise, I see a few things:


It's not quite PEP8, the coding style. Whilst you can read it, which is always good, there are tools to automatize the process, such as flake8, black. Most likely, your editor will have a plugin. 

This is include things like underscore_names in lieu of camelCasing.

Note that this standard is a living document, and gets updated once in a while.
None is a singleton in Python, and thus you can use the is keyword instead.
Python relies on its id() function to get a hash of an object, and compare them.
As None is a singleton, the hash is the same. 

So your line if node == None: could be if node is None.
Going further this way, None evaluates to False in a test, so you could go if not node: (edit: as discussed with @Gloweye, it's indeed clearer and preferred to use the first variant).
Python returns None when no value is being explicitly returned, whether you have no return in a function, or do a blank return.


These two lines taken together could then be:

if node is None:
    return


and would be considered idiomatic.


Lastly, in Python3 (which you ought to be using), class definition have been revamped. The way you do it:


class TST(object):


is now:

class TST:


If you were inheriting from something, though, it would indeed be:

class TST(ParentClass):


Maybe what you could try next is to implement unit tests with unittest or pytest and see whether your structure holds on with more convoluted cases.