Using enumerate in Python while looping (#25221)

* Using enumerate in Python while looping

enumerate follows the zen of Python. enumerate makes the code more readable

* fixed bug in python linear search
This commit is contained in:
Nitin Chauhan
2019-01-08 20:32:12 +05:30
committed by Manish Giri
parent 181fea9e8e
commit 9de5460b92

View File

@ -120,9 +120,9 @@ int linear_search(int arr[],int n,int num)
### Example in Python
```python
def linear_search(array, num):
for i in range(len(array)):
if (array[i]==num):
return i
for index, element in enumerate(array):
if element == num:
return index
return -1
```