Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sequence = [1, 2, 3, 4, 5]
- def linear_search(sequence, posn):
- for position in range(len(sequence)):
- if sequence[position] == posn:
- #print(sequence[position], "is at position ", str(position + 1))
- return position + 1
- return False
- print(linear_search(sequence, 2))
- def linear_sorted_search(sequence, posn):
- for position in range(len(sequence)):
- if sequence[position] == posn:
- #print(sequence[position], "is at position ", str(position + 1))
- return position + 1
- elif sequence[position] > posn:
- return False
- else:
- return False
- print(linear_sorted_search(sequence, 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement