Why does print work in my function but not return?


#1

My code works as is below but on line 4 I originally had return y[key] and it didn't work. Why is that?


def hardcopy(x):
    for y in x:
        for key in y:
            print y[key]
            
print hardcopy(students)


#2

Once a function returns, it exits and no longer runs.


#3

Makes sense, so in this case using print takes the place of return (and acts kind of the same way) so the function can loop?


#4

The way I use return in these sorts of ways, is via appending to an array.

Example:

def hardcopy(x):
    final = []
    for y in x:
        for key in y:
            final.append(y[key])
    return final

#5

Ahh yes I remember this from a coursera python course I took early last year. Thanks for reminding me.