From b41e5035751c092fc5c9bcda2314aad8c6d8bade Mon Sep 17 00:00:00 2001 From: divya116 <56511764+divya116@users.noreply.github.com> Date: Wed, 16 Oct 2019 11:24:49 +0530 Subject: [PATCH] linear-search.py Added linear search code in python --- Algorithms/Search/linear-search.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Algorithms/Search/linear-search.py diff --git a/Algorithms/Search/linear-search.py b/Algorithms/Search/linear-search.py new file mode 100644 index 0000000..66dde53 --- /dev/null +++ b/Algorithms/Search/linear-search.py @@ -0,0 +1,9 @@ +#Code to return first index of occurrence of element x if it is present in array arr, -1 if not present +def search(arr, x): + + for i in range(len(arr)): + + if arr[i] == x: + return i + + return -1