Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

linear search python

"""
Ordered Linear Search
- This version searches for 1 item, and returns all the occurrences of it
"""
def ord_lin(lst, item):
    found = []
    
    # Search list up to larger number, and get all indices where its found
    for i, num in enumerate(lst): 
        if num > item:
            break
        elif num == item:
            found.append(i)
    return found
 
PREVIOUS NEXT
Tagged: #linear #search #python
ADD COMMENT
Topic
Name
6+3 =