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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:21:07+00:00 2026-06-15T03:21:07+00:00

Is there any pre-made optimized tool/library in Python to cut/slice lists for values less

  • 0

Is there any pre-made optimized tool/library in Python to cut/slice lists for values “less than” something?

Here’s the issue: Let’s say I have a list like:

a=[1,3,5,7,9]

and I want to delete all the numbers which are <= 6, so the resulting list would be

[7,9]

6 is not in the list, so I can’t use the built-in index(6) method of the list. I can do things like:

#!/usr/bin/env python
a = [1, 3, 5, 7, 9]
cut=6
for i in range(len(a)-1, -2, -1):
    if a[i] <= cut:
        break
b = a[i+1:]
print "Cut list: %s" % b

which would be fairly quick method if the index to cut from is close to the end of the list, but which will be inefficient if the item is close to the beginning of the list (let’s say, I want to delete all the items which are >2, there will be a lot of iterations).

I can also implement my own find method using binary search or such, but I was wondering if there’s a more… wide-scope built in library to handle this type of things that I could reuse in other cases (for instance, if I need to delete all the number which are >=6).

Thank you in advance.

  • 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-15T03:21:08+00:00Added an answer on June 15, 2026 at 3:21 am

    You can use the bisect module to perform a sorted search:

    >>> import bisect
    >>> a[bisect.bisect_left(a, 6):]
    [7, 9]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a canonical colorspace conversion library? I can't find any pre-existing solutions. Is
Are there any pre-made scripts that I can use for PHP / MySQL to
Hi are there any good Joomla extensions or pre made website to use as
Are there any pre-existing solutions out there which would extend the built in SQL
Is there any way to pre compile stored procedures in SQL Server? My requirement
Are there any attributes to pre select some radio button in tag on page
Is there any functional difference in Python between a try statement and an if
Is there any way in Notepad++ (or even with another tool) to change the
Is there any way I can set a formatter on models that will convert
Are there any recommended libraries, patterns or examples on how to implement Prefetching and/or

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.