Lineare Suche in Python

Der Code für die lineare Suche ist unten.

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()

Das Ausführungsergebnis ist wie folgt.

Found!

Vielen Dank für das Lesen bis zum Ende. Lass uns nochmal treffen.

Recommended Posts

Lineare Suche in Python
Binäre Suche in Python
Binäre Suche in Python / C ++
Algorithmus in Python (Dichotomie)
Online lineare Regression in Python
Algorithmus in Python (Breitenprioritätssuche, bfs)
Schreiben Sie eine Dichotomie in Python
Algorithmus in Python (Tiefenprioritätssuche, dfs)
Beherrsche die lineare Suche! ~ Python-Implementierungsversion ~
Schreiben Sie eine Suche mit Tiefenpriorität in Python
Suche nach Tiefenpriorität mit Stack in Python
Quadtree in Python --2
Python in der Optimierung
CURL in Python
Geokodierung in Python
SendKeys in Python
Metaanalyse in Python
Unittest in Python
Epoche in Python
Zwietracht in Python
Deutsch in Python
DCI in Python
Quicksort in Python
nCr in Python
N-Gramm in Python
Programmieren mit Python
Plink in Python
Konstante in Python
FizzBuzz in Python
SQLite in Python
Schritt AIC in Python
LINE-Bot [0] in Python
CSV in Python
Reverse Assembler mit Python
Reflexion in Python
Konstante in Python
nCr in Python.
Format in Python
Scons in Python 3
Puyopuyo in Python
Python in Virtualenv
PPAP in Python
Quad-Tree in Python
Reflexion in Python
Chemie mit Python
Hashbar in Python
DirectLiNGAM in Python
LiNGAM in Python
In Python reduzieren
In Python flach drücken
Echte Werte und Eigenvektoren: Lineare Algebra in Python <7>
Online lineare Regression in Python (Robuste Schätzung)
Suchen und spielen Sie YouTube-Videos mit Python
Lineare Unabhängigkeit und Basis: Lineare Algebra in Python <6>
Auf der Suche nach dem schnellsten FizzBuzz in Python
Einführung in Vektoren: Lineare Algebra in Python <1>