Hackbright Code Challenges

Show Even Numbers: Solution

Show Even Numbers: Solution

Problem

Show Even Numbers

Whiteboard

Easier

Challenge

Easier

Concepts

Loops

Download

show-evens-solution.zip


def show_evens(nums):
    """Given list of ints, return list of *indices* of even numbers in list."""

    # START SOLUTION

    out = []

    for i in range(len(nums)):
        if nums[i] % 2 == 0:
            out.append(i)

    return out

You could also do this with the enumerate function, which allows you to iterate over a list getting both the current item and the index at once.