Linear search in Python

The code for the linear search is below.

def linear_search(src, target_value):
    result = False
    for i in range(len(src)):
        if src[i] == target_value:
            result = True
    return result


def main():
    src = [1, 2, 3, 4, 5]
    target_value = 5

    if linear_search(src, target_value):
        print('Found!')
    else:
        print('Not Found')


if __name__ == '__main__':
    main()

The execution result is as follows.

Found!

Thank you for reading until the end. Let's meet again.

Recommended Posts

Linear search in Python
Binary search in Python (binary search)
Search for strings in Python
Binary search in Python / C ++
Algorithm in Python (binary search)
Online linear regression in Python
Algorithm in Python (breadth-first search, bfs)
Write a binary search in Python
Algorithm in Python (depth-first search, dfs)
Master linear search! ~ Python implementation version ~
Write a depth-first search in Python
Depth-first search using stack in Python
Quadtree in Python --2
Python in optimization
CURL in python
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Basic Linear Algebra Learned in Python (Part 1)
Algorithm learned with Python 9th: Linear search
Eigenvalues and eigenvectors: Linear algebra in Python <7>
Online Linear Regression in Python (Robust Estimate)
Search and play YouTube videos in Python
Linear Independence and Basis: Linear Algebra in Python <6>
In search of the fastest FizzBuzz in Python
Introduction to Vectors: Linear Algebra in Python <1>