Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:46:44+00:00 2026-06-15T02:46:44+00:00

From this site , it says that list.index() is a linear search through the

  • 0

From this site, it says that list.index() is a linear search through the list.

And it also seems like in is also linear.

Is there any advantage to using one over the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:46:45+00:00Added an answer on June 15, 2026 at 2:46 am

    If you want to compare different python approaches, such as the in operator versus .index(), use the timeit module to test the speed differences. Python data type complexities are documented on http://wiki.python.org/moin/TimeComplexity.

    Do note that there is a big difference between in and .index(); the first one returns a boolean, the latter the index of the found item (an integer) or it’ll raise an exception. It thus is (slightly) slower for the average case:

    $ python -mtimeit -s 'a = list(range(10000))' '5000 in a'
    10000 loops, best of 3: 107 usec per loop
    $ python -mtimeit -s 'a = list(range(10000))' 'a.index(5000)'
    10000 loops, best of 3: 111 usec per loop
    

    If you need to optimize for membership testing, use a set() instead:

    $ python -mtimeit -s 'a = set(range(10000))' '5000 in a'
    10000000 loops, best of 3: 0.108 usec per loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from this site there is header compress.h http://www.fredosaurus.com/notes-cpp/examples/compress/compress.html i am using visual c++ 2010
I have a site with a SELECT statement like this: SELECT * FROM MyTable
I got streaming error on this site http://68.233.16.160/news/7 says something like 200 stream not
So, I lifted this nice AJAX code from another site. Problem is that I
I am using a CSS Tree Menu from this site: http://www.thecssninja.com/css/css-tree-menu I can't seems
From this site (http://www.ipv6.com/articles/general/IPv6-Header.htm) , it says: Packet priority/Traffic class (8 bits) The 8-bit
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I'm trying to get information from this site: http://www.gocrimson.com/sports/mbkb/2011-12/roster If you look at that
I'm using two functions one is from this site http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/ and its using function
I have downloaded the sample code from this site for FTP Client http://www.lysesoft.com/products/andftp/index.html But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.