From e676a7a38ff88fdf45df16b1a467fd2cb744ffc7 Mon Sep 17 00:00:00 2001 From: KaramSahoo <51832871+KaramSahoo@users.noreply.github.com> Date: Thu, 17 Oct 2019 19:38:03 +0530 Subject: [PATCH] Update Linear Search.py --- Python/Linear Search.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Python/Linear Search.py b/Python/Linear Search.py index a182daa..4ffbc1b 100644 --- a/Python/Linear Search.py +++ b/Python/Linear Search.py @@ -2,19 +2,18 @@ # If x is present then return its location, # otherwise return -1 -def search(arr, n, x): +def search(arr, x): - for i in range (0, n): - if (arr[i] == x): + for i in arr: + if (i == x): return i; return -1; # Driver Code arr = [ 2, 3, 4, 10, 40 ]; x = 10; -n = len(arr); -result = search(arr, n, x) +result = search(arr, x) if(result == -1): print("Element is not present in array") else: - print("Element is present at index", result); + print("Element is present at index", arr.index(result));