recurDescents(p) and recurAncestors(p)
<p>I need to write a Python script with two functions. One function is to return the descendants children of (p) and Take (p) and return ancestors of (p). </p>

<p>I made a script that returns the children of (p). </p>

<pre><code>parent = [("Homer","Bart"),("Homer","Lisa"),("Abe","Homer"),("Bart","Jim"),("Jim","Kim"),("Lisa","Lora")]

def child(p): #definition of child function()
    result = []    
    for x in parent:
        if x[0] == p:
            print(x[1])
            result.append(x[1])


        return result

def grandChild (p):
    result = []
    children = child(p)
    for x in children:
        for y in parent:
            if x == y[0]:
                result.append(y(1))
            return result



p = "Homer"
children = child(p) # my caller question
print(p, " has child ", children)
</code></pre>

<p>I just can't figure out what to do.</p>

<p>Your return statements are in the wrong places.  They should be outside the loops:</p>

<pre><code>def f():
    for loop
        stuff
    return ...
</code></pre>

<p>If you want a slightly more concise version:</p>

<pre><code>#find children of parent p
[child for parent, child in list_of_parents if parent == p]
#find parent of child c
[parent for parent, child in list_of_parents if child == c]
</code></pre>

python python-3.x