From 858adea7620ddbb4666920379c07d0cb40266aab Mon Sep 17 00:00:00 2001 From: cronousz Date: Fri, 20 Oct 2023 00:24:19 +0700 Subject: [PATCH] addded file linear-array-finder using python programs --- L/linear-array-finder/linear-array-finder.py | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 L/linear-array-finder/linear-array-finder.py diff --git a/L/linear-array-finder/linear-array-finder.py b/L/linear-array-finder/linear-array-finder.py new file mode 100644 index 00000000..ef796f9a --- /dev/null +++ b/L/linear-array-finder/linear-array-finder.py @@ -0,0 +1,22 @@ + + +# Searching an element in a list/array in python +# can be simply done using \'in\' operator +# Example: +# if x in arr: +# print arr.index(x) + +# If you want to implement Linear Search in python + +# Linearly search x in arr[] +# If x is present then return its location +# else return -1 + +def search(arr, x): + + for i in range(len(arr)): + + if arr[i] == x: + return i + + return -1 \ No newline at end of file