Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #First, we declare the function:
- def linear(a_list, an_item):
- #Then, we iterate through the list:
- for i in range(len(a_list)):
- #If we've found the item, we're done! Go ahead and return this index.
- if a_list[i] == an_item:
- return i
- #If we reach the end of the function it means we never returned an index, which means we never found the item and can return False.
- return False
- a_list = [5, 1, 3, 6, 7, 3, 1, 6, 7, 8, 3, 6]
- print(linear(a_list, 6))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement