Using a return inside of a loop will break it and exit the function even if the iteration is still not finished.

For example:

def num():
    # Here there will be only one iteration
    # For number == 1 => 1 % 2 = 1
    # So, break the loop and return the number
    for number in range(1, 10):
        if number % 2:
            return number
>>> num()
1

In some cases we need to break the loop if some conditions are met. However, in your current code, breaking the loop before finishing it is unintentional.

Instead of that, you can use a different approach:

Yielding your data

def show_todo():
    # Create a generator
    for key, value in cal.items():
        yield value[0], key

You can call it like:

a = list(show_todo())  # or tuple(show_todo())

or you can iterate through it:

for v, k in show_todo(): ...

Putting your data into a list or other container

Append your data to a list, then return it after the end of your loop:

def show_todo():
    my_list = []
    for key, value in cal.items():
        my_list.append((value[0], key))
    return my_list

Or use a list comprehension:

def show_todo():
    return [(value[0], key) for key, value in cal.items()]
Answer from Chiheb Nexus on Stack Overflow
🌐
Python Forum
python-forum.io › thread-31529.html
returning values in for loop
in my example i would like to return the whole list with it being in a function instead i am only getting 1 as a return. However when its not in a function i will get the full list. So my question is how can i put this for loop in a function and have...
🌐
Learn Python
learnpython.dev › 02-introduction-to-python › 110-control-statements-looping › 40-break-continue
break, continue, and return :: Learn Python by Nina Zakharenko
They’re a concept that beginners to Python tend to misunderstand, so pay careful attention. The break statement will completely break out of the current loop, meaning it won’t run any more of the statements contained inside of it. >>> names = ["Rose", "Max", "Nina", "Phillip"] >>> for name in names: ...
🌐
Foundry
community.foundry.com › discuss › topic › 146804 › how-to-return-value-from-for-loop-in-python
How to return value from For loop in python?
Community · Community Home · Discuss · Cattery · Share · Watch · Home The Foundry Visionmongers Limited is registered in England and Wales
🌐
Codecademy
codecademy.com › forum_questions › 52faa5d4282ae36d190023b3
8/9 Does return "break" a loop? | Codecademy
This is because the return function signals the end of a function - it’s only used as the last command in a function to send data back to the class or function that called it, Once it reads a return, python assumes that it is the last command ...
Find elsewhere
🌐
Real Python
realpython.com › python-return-statement
The Python return Statement: Usage and Best Practices – Real Python
June 14, 2024 - The return statement breaks the loop and returns immediately with a return value of True. If no value in iterable is true, then my_any() returns False. This function implements a short-circuit evaluation.
🌐
Quora
quora.com › How-do-you-return-to-the-beginning-of-a-loop-in-Python
How to return to the beginning of a loop in Python - Quora
Answer (1 of 4): As soon as the last statement of the loop finishes running, Python will automatically return to the beginning of the loop - and re-evaluate the condition (for a while loop), or run the loop for the next element in an iterable ...
🌐
Rip Tutorial
riptutorial.com › return statement inside loop in a function
Python Language Tutorial => Return statement inside loop in a function
def func(params): for value in params: print ('Got value {}'.format(value)) if value == 1: # Returns from function as soon as value is 1 print (">>>> Got 1") return print ("Still looping") return "Couldn't find 1" func([5, 3, 1, 2, 8, 9]) output · Got value 5 Still looping Got value 3 Still looping Got value 1 >>>> Got 1 · PDF - Download Python Language for free ·
🌐
Codecademy Forums
discuss.codecademy.com › computer science
For Loop return - Computer Science - Codecademy Forums
April 19, 2023 - Hello, I am confused with my code, how can I return the last result of my for loop. Thank you # Write your first_three_multiples function here def first_three_multiples(num): for i in range(1,4): result = num * i print(result) return result first_three_multiples(10) # should print 10, 20, 30, and return 30 first_three_multiples(0) # should print 0, 0, 0, and return 0
🌐
Python.org
discuss.python.org › ideas
Getting generator return values with natural for loop syntax - Ideas - Discussions on Python.org
July 30, 2024 - Currently, if we have a return value in a generator definition, it’s cumbersome to be able to retrieve that value. We won’t be able to directly use for loop, because the StopIteration exception is getting swallowed. For example: def generator(): for i in range(3): yield i return -1 To retrieve the -1, we need to do this: itr = generator() while True: try: value = next(itr) print(value) except StopIteration as e: return_value = e.value ...
🌐
Quora
quora.com › Can-a-return-statement-be-used-inside-an-if-block-or-a-for-loop
Can a return statement be used inside an if block or a for loop? - Quora
Answer (1 of 13): Yes, absolutely. There are two camps around this topic. Some people are convinced that a function must have one and only one return point, to be considered correctly structured. Others say that as soon as the result of a function is clear, you should immediately return the valu...
🌐
Python Morsels
pythonmorsels.com › breaking-out-of-a-loop
Breaking out of a loop - Python Morsels
June 26, 2025 - At this point, it might actually be easier to put this code into a function, and use return to break out of that inner loop as well as the outer loop at the same time. In addition to the break statement, Python also has a continue statement: with open("numbers.txt") as number_file: total = 0 for line in number_file: for number in line.split(): n = float(number) if n < 0: print("Skipping negative", n) continue print("Adding", n) total += n print("Total:", total)
🌐
Python
wiki.python.org › moin › ForLoop
ForLoop - Python Wiki
For loop from 0 to 2, therefore running 3 times. for x in range(0, 3): print("We're on time %d" % (x))
🌐
Dataquest
dataquest.io › blog › tutorial-how-to-write-a-for-loop-in-python
Tutorial: How to Write a For Loop in Python – Dataquest
March 11, 2025 - The int() method converts the iterable to its iterator, and the next() method returns the items in the iterable one after the other. A for loop operation is similar to calling the iter() method on an iterable to get an iterator, as well as the ...