Changing a global variable in a function without using global keyword
<p><a href="http://i.stack.imgur.com/EQUph.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/EQUph.jpg" alt="screenshot of code from a textbook"></a></p>

<p>Here is my code:</p>

<pre><code>def L_value_Change(k):
    global L
    L = k
    return L

def  applyF_filterG(L, f, g):
    L
    k = []
    for i in L:
       if g(f(i)):
          k.append(i)
    L = k
    L_value_Change(k)
    if L == []:
        return -1
    else :
        return max(L)
</code></pre>

<p>When I put this code, the grader tells me it's incorrect! So I read the introduction to the quiz, the instructor wrote "global variables don't work". How could I change the <code>L</code> variable with a function without using the word <code>global</code>? If you try my code and gave it the required input, it will give you a right answer, but the grader tells me it's wrong.</p>

<p>Here's my code which avoids mutating on the list that you're trying to iterate upon.    </p>

<pre><code>def applyF_filterG(L,f,g):
        """
        Assumes L is a list of integers
        Assume functions f and g are defined for you. 
        f takes in an integer, applies a function, returns another integer 
        g takes in an integer, applies a Boolean function, 
            returns either True or False
        Mutates L such that, for each element i originally in L, L contains  
            i if g(f(i)) returns True, and no other elements
        Returns the largest element in the mutated L or -1 if the list is empty
        """
        # Applying the functions &amp; Mutating L
        i = len(L)-1
        largestnum=0  
        if (len(L)==0):
            return -1
        else:
            while i&gt;=0:
                if not g(f(L[i])):
                   del L[i]
                i-=1    

        #Finding the largest number
        if not L:
            return -1
        if (len(L)==1):
            return L[0]
        else:
            for num in range(len(L)-1):
                if (L[num]&gt;L[num+1]):
                    largestnum=L[num]
                else:
                    largestnum=L[num+1]
            return largestnum    
</code></pre>

python python-3.x