Created
March 24, 2019 19:12
-
-
Save iMel408/bba8c57286eed0cfb63e171e6b8bccf0 to your computer and use it in GitHub Desktop.
multi linear search using enumerate method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ex_list = [0,1,0,2,3,4,5,6,0,8,9,10] | |
def linear_search_multi(list, element): | |
""" find all index positions of a given element within a list""" | |
positions = [] | |
for i, v in enumerate(list): | |
if list[i] == element: | |
positions.append(i) | |
return positions | |
print(linear_search_multi(ex_list,0)) | |
# [3, 7, 11] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment