Skip to content

Instantly share code, notes, and snippets.

@iMel408
Created March 24, 2019 19:12
Show Gist options
  • Save iMel408/bba8c57286eed0cfb63e171e6b8bccf0 to your computer and use it in GitHub Desktop.
Save iMel408/bba8c57286eed0cfb63e171e6b8bccf0 to your computer and use it in GitHub Desktop.
multi linear search using enumerate method.
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