'How to implement a decision tree for the graph

I was given a graph to write a function that implements a decision tree. Can you give any hints or explain what libraries I should use or maybe share some useful links. I tried to go the dumb way and this is what I got. Apparently it wasn't accepted because the cyclomatic complexity was exceeded.

def main(x):
    if x[4] == 1996:
        if x[0] == 1987:
            if x[3] == 'GAMS':
                return 0 if x[2] == 2020 else 1
            elif x[3] == 'CLICK':
                return 2 if x[2] == 2020 else 3
            elif x[3] == 'FORTH':
                return 4
        elif x[0] == 1986:
            if x[2] == 2020:
                if x[1] == 'TLA':
                    return 5
                elif x[1] == 'COBOL':
                    return 6
                elif x[1] == 'ASP':
                    return 7
            if x[2] == 1995:
                return 8
    else:
        return 9 if x[2] == 2020 else 10

Function call:

x = main([1987, 'COBOL', 2020, 'CLICK', 1996])  # 2
y = main([1986, 'ASP', 2020, 'CLICK', 1996])  # 7
print(x, y)

output:

2 7


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source