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>Lists are <strong>mutable</strong> objects, and as such, to change them all you have to do is just pass them as an argument to the function. </p>

<pre><code>def f(i):
    return i + 2

def g(i):
    return i &gt; 5

l = [0, -10, 5, 6, -4]
def applyF_filterG(L, f, g):
    for val in L[:]:
        if not g(f(val)):
            L.remove(val)
    return -1 if not L else max(L)      

print(l) # [0, -10, 5, 6, -4]
applyF_filterG(l, f, g) # Return 6
print(l) # [5, 6]
</code></pre>

python python-3.x