Plotting state diagram from list of string in python

Viewed 17

I am currently using graphviz to generate a state diagram for the elements present in my list

states = ['abcd','efghi','gfhfhf','scsjhc','scfhsvcj','sjhcbhcb',...."FAILED gsdhjcvdjc"]

length of list is 20

for i in range(len(states)):
    string = states[i]
    print("this is string -------->",string)
    if (re.search("FAILED",string)):
        print("This is inside if ------------------>",states[i])
        g.node(states[i-1],states[i], fillcolor = "red", style = "filled")
        break
    elif i == (len(states)-1):
        print("This is inside elif ---------------->",states[i])
        g.node(states[i-1],states[i], fillcolor = "green", style = "filled")
        break
    else:
        #print("This is inside else ---------------->",states[i])
        g.node(states[i-1],states[i], fillcolor = "green", style = "filled")
        g.edge(states[i-1],states[i])
g.view()

At the end my flow diagram is not getting formed correctly..

Ask is "The list can contain last element which starts with "FAILED" or might not, but the flow of the elements should be one after other...only if list has last element as FAILED then that particular element must be printed in red.

What can be done ?

0 Answers
Related