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
|
||||
```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
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user