This code scales each leaf by a factor, but i dont understand one part of the function
<pre><code>#checking if node is a leaf
def is_leaf(item):  
    return type(item) != tuple

#performing function on every element in sequence
def map(fn, seq):
    if seq == ():
        return ()
    else:
        return (fn(seq[0]), ) + map(fn, seq[1:])

#scaling each leaf by factor
def scale_tree(tree, factor):
    def scale_func(subtree):         **#dont understand this part**
        if is_leaf(subtree):
            return factor * subtree
        else:
            return scale_tree(subtree, factor)
    return map(scale_func, tree)

tup = ((3, 2), 1, (4,), 5)      
print(scale_tree(tup, 2))
</code></pre>

<p>how does the function scale_func know what is the argument to be called if it is not stated like scale_tree?</p>

<p>Have a look at the <a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow">definition</a> of the map function.</p>

<p><code>map(scale_func, tree)</code> will apply every item of tree to the function <code>scale_func</code>.</p>

<p>So the argument <code>subtree</code>will be sequentially assigned all items of <code>tree</code>.</p>

python