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 6389915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:27:48+00:00 2026-05-25T03:27:48+00:00

In Python, how do you find the index of the first value greater than

  • 0

In Python, how do you find the index of the first value greater than a threshold in a sorted list?

I can think of several ways of doing this (linear search, hand-written dichotomy,..), but I’m looking for a clean an reasonably efficient way of doing it. Since it’s probably a pretty common problem, I’m sure experienced SOers can help!

Thanks!

  • 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-05-25T03:27:49+00:00Added an answer on May 25, 2026 at 3:27 am

    Have a look at bisect.

    import bisect
    
    l = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
    
    bisect.bisect(l, 55) # returns 7
    

    Compare it with linear search:

    timeit bisect.bisect(l, 55)
    # 375ns
    
    
    timeit next((i for i,n in enumerate(l) if n > 55), len(l))
    # 2.24us
    
    
    timeit next((l.index(n) for n in l if n > 55), len(l))
    # 1.93us
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In python to find the index of the minimum value of the array I
What would be the most efficient\elegant way in Python to find the index of
Often when I'm using Python I'll find myself writing list comprehensions that look something
I find it extremely useful when doing Django/Python web development to fully inspect a
I am really new to python and I can't find any information about this.
I'm using pymongo: http://api.mongodb.org/python/1.9%2B/index.html for post in db.datasets.find({set:flickr}).sort(num_favs,-1): ... How come I can't sort
I need to set an environment variable in Python and find the address in
I have written a Python program to find the carrier of a cell phone
I've been trying to find a python code that would log in to my
I'm trying to use a Python regex to find a mathematical expression in a

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.