'Creating a variable from the outcome of an if statement in python

I have an if statement which returns a value depending on a string value being present in a list. I want to take the return value of the string value present and make a global variable or a variable outside of the if statement.

Then I want to apply value of the variable to another if statement in another function. Each time the code iterates I want it to update the variable output. The first iteration of the for loop sets the initial condition of (A B C OR D) and then the following iterations use that initial condition and does something to it depending on (E F G OR H).

Below is some code, any help would be hugely appreciated.

def a_func(this):
    if this  == 'A':
        a()
        return 'A'
    elif this  == 'B':
        b()
        return 'B'
    elif this  == 'C':
        c()
        return 'C'
    elif this  == 'D':
        d()
        return 'D'
    else:
        pass

output = a_func(this)

def new_func(output):
    if output == 'C':
        if this == 'E':
            d()
            return 'D'
        elif this == 'F':
            b()
            return 'B'
        elif this == 'G':
            c()
            return 'C'
        

    elif output == 'D':
        if this == 'E':
            d()
            return 'D'
        elif level == 'F':
            c()
            return 'C'
        elif level == 'G':
            d()
            return 'D'
    else:
        pass
output = new_func(output)

for this in that:
    do the above


Sources

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

Source: Stack Overflow

Solution Source