Code › codeit-ai-sprint

Reviewing Lists and For Loops in Python

A short Codeit AI Engineer Sprint pre-course note on revisiting Python lists and for loops

Today I continued the pre-course with Programming and Data in Python, mostly around lists and for loops.

The previous course was more about getting the basic Python syntax back into my hands. This one starts to feel closer to working with data. It covered creating lists, reading values by index, sorting, using list functions, and then moving into for loops and the range function. I am only about halfway through the course, so this is still basic material, but the shape of data handling in Python is starting to come back.

The first thing I revisited was the list. The idea itself is familiar. Every language has some version of arrays, lists, or collections. What stood out again is how lightly Python lets me express the same operations. Pulling out a value, changing order, applying a helper function, and moving on to the next step all feel fairly direct.

For loops felt similar. The concept is not new, but in Python they feel natural when paired with lists. Take each value, do something with it, or use range when the number of repetitions matters.

Two exercises were more interesting than they first looked: Pythagorean triples and reversing a list. With Pythagorean triples, the first approach that comes to mind is often three nested loops over a, b, and c. But if the sum is fixed, c does not need its own loop. If the total is 400, c can be calculated as 400 - a - b, which removes one loop.

for a in range(1, 400):
    for b in range(a + 1, 400):
        c = 400 - a - b
        if a * a + b * b == c * c and a < b < c:
            print(a * b * c)

Even in a basic exercise, that kind of small reduction makes the problem more interesting. It is the same habit that shows up later in algorithm problems: avoid work when the value can be derived.

Reversing a list had a similar point. Instead of walking through the whole list, I only need to go to the halfway point and swap the values on both sides. Python’s tuple unpacking makes the swap short.

numbers = [1, 2, 3, 4, 5]

for i in range(len(numbers) // 2):
    j = len(numbers) - 1 - i
    numbers[i], numbers[j] = numbers[j], numbers[i]

That part felt less about syntax and more about the way of thinking. I have to look at the length of the list, the midpoint, and the index on the other side before the code becomes natural. Even when the concept is familiar, typing it out in Python helps me see how the language wants the idea to be expressed.

Once the course moves into AI, I will keep dealing with data anyway. Inputs, model responses, logs, evaluation results, and probably many small transformations in between. Lists and loops are basic, but they sit underneath a lot of that work.

So today’s study was less about learning something new and more about getting the Python data-handling rhythm back. If I keep cleaning up these basics now, the main course should feel less interrupted later.