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:
committed by
Manish Giri
parent
181fea9e8e
commit
9de5460b92
@ -120,9 +120,9 @@ int linear_search(int arr[],int n,int num)
|
|||||||
### Example in Python
|
### Example in Python
|
||||||
```python
|
```python
|
||||||
def linear_search(array, num):
|
def linear_search(array, num):
|
||||||
for i in range(len(array)):
|
for index, element in enumerate(array):
|
||||||
if (array[i]==num):
|
if element == num:
|
||||||
return i
|
return index
|
||||||
return -1
|
return -1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user