In Python, we can use in to search in strings, lists, sets, etc. like
if x in string:
But which search algorithm is internally implemented?
            Asked
            
        
        
            Active
            
        
            Viewed 114 times
        
    1
            
            
        
        CoolCoder
        
- 786
 - 7
 - 20
 
- 
                    1The duplicate only answers your question for strings, but the implementation is different for each type anyway. You might consider reading the source code for CPython for a specific implementation. – Selcuk Apr 12 '21 at 02:07
 
1 Answers
1
            
            
        The implemented search algorithm is at the vendor's discretion. You need to consult your vendor's documentation for that. Also note that the algorithm will vary by data type: unrestricted sequences will require some form of linear search; sorted ones will have bisection or interpolation; dicts and sets use a constant-time hash key.
        Prune
        
- 76,765
 - 14
 - 60
 - 81