fastest list index searching

Switch to Dreamhost, and we will move your web site. No kidding.

Someone was looking for fastest list index searching (in Python) in stackoverflow. There are only four elements in the list, still it was as issue for him, as it was used in an inner-loop and the profiler identified that, this part was executing the most. He tried several approaches.

1. This is the most obvious one:

if value in mylist:
return mylist.index(value)

Here the problem is, in the condition used in if, it takes O(n) time to check if the value is in the list, and the return statement…

A historical timeline of Codango™

Original Source

#codango #developer #development #coder #coding

We're happy to share this resource that we found. The content displayed on this page is property of it's original author and/or their organization.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*