I have a program that looks something like (this is a silly example to illustrate my point, what it does is not very important)
count = 0
def average(search_term):
    average = 0
    page = 0
    current = download(search_term, page)
    while current:
        def add_up(downloaded):
            results = downloaded.body.get_results()
            count += len(results)
            return sum(result.score for result in results)
        total = average*count
        total += add_up(current)
        average = total/count
        print('Average so far: {:2f}'.format(average))
        page += 1
        current = download(search_term, page)
If I have the cursor on any of the lines 8–11 and press a key combination I want Emacs to copy or kill the add_up function, and then I want to move the cursor to line 2 and press a key combination and paste the function there, with the correct level of indentation for the context it is pasted in.
Is this possible, and if so, how would I do that?
python-modethat ships with Emacs.