Advertisement
k1alo

Search.index

Dec 14th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. def sequential_search_all(arr, target):
  2.     indices = []
  3.     for i in range(len(arr)):
  4.         if arr[i] == target:
  5.             indices.append(i)
  6.     return indices
  7.  
  8. array = ["apple", "banana", "cherry", "date", "elderberry", "cherry"]
  9. target = "cherry"
  10.  
  11. results = sequential_search_all(array, target)
  12. if len(results) > 0:
  13.     print(f"Элемент {target} найден в массиве на позициях: {results}.")
  14. else:
  15.     print(f"Элемент {target} не найден в массиве.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement