What is the big O of the following if statement
?
if \"pl\" in \"apple\":
...
What is the overall big O of how python determ
You can use timeit and test it yourself:
maroun@DQHCPY1:~$ python -m timeit 's = "apple";s.find("pl")'
10000000 loops, best of 3: 0.125 usec per loop
maroun@DQHCPY1:~$ python -m timeit 's = "apple";"pl" in s'
10000000 loops, best of 3: 0.0371 usec per loop
Using in
is indeed faster (0.0371 usec compared to 0.125 usec).
For actual implementation, you can look at the code itself.