Sample Analysis of search in python
This article will explain in detail the sample analysis of search in python. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. General search
Search is the algorithmic process of finding a particular element from a collection of elements. The search process usually returns True or False, indicating whether the element exists, respectively.
The in method is provided in python to determine whether the element exists in the list:
# python provides in function to search a = [3 in 4 5 pm 8 in']'t'in a9 search a
The results are as follows:
two。 Sequential search
Sequential search for the meaning of the name: start with the first element in the list and look at it one by one in the default order until you find the target element or check the list. If the target element is not found after checking the list, the target element is not in the list.
Sequential search process:
1.1 Sequential search under disorder
The sequential search under disorder is very characteristic, the list is out of order, so we have to compare and find the elements one by one.
# sequential search def sequentialsearch (testlist,item): pos=0 found=False while pos