Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/algorithms-in-code/linear-search-in-code-video.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1007 B

id, title, challengeType, videoId, dashedName
id title challengeType videoId dashedName
698dca057932b3cc4b19c926 Linear Search in Code 11 bKkgjdPkL3A linear-search-in-code

--description--

In this video, you will code out the linear search algorithm using Python.

--questions--

--text--

Which of the following is the correct way to write a linear search function?

--answers--

def linear_search(list, target):
    for i in range(len(list) - 1):  
        if list[i] == target:
            return i
    return -1

def linear_search(list, target):
    for i in range(len(list)):
        if i == target:   
            return i
    return -1


def linear_search(list, target):
    for i in range(len(list)):
        if list[i] == target:
            return i
        else:
            return -1  

def linear_search(list, target):
    for i in range(len(list)):
        if list[i] == target:
            return i  
    return None

--video-solution--

4