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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:16:44+00:00 2026-06-16T04:16:44+00:00

If I have a long unsorted list of 300k elements, will sorting this list

  • 0

If I have a long unsorted list of 300k elements, will sorting this list first and then do a “for” loop on list speed up code? I need to do a “for loop” regardless, cant use list comprehension.

sortedL=[list].sort() 

for i in sortedL:
  (if i is somenumber)
     "do some work"

How could I signal to python that sortedL is sorted and not read whole list. Is there any benefit to sorting a list? If there is then how can I implement?

  • 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-16T04:16:46+00:00Added an answer on June 16, 2026 at 4:16 am

    It would appear that you’re considering sorting the list so that you could then quickly look for somenumber.

    Whether the sorting will be worth it depends on whether you are going to search once, or repeatedly:

    • If you’re only searching once, sorting the list will not speed things up. Just iterate over the list looking for the element, and you’re done.

    • If, on the other hand, you need to search for values repeatedly, by all means pre-sort the list. This will enable you to use bisect to quickly look up values.

    The third option is to store elements in a dict. This might offer the fastest lookups, but will probably be less memory-efficient than using a list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I have long list of buttons: <input type=button name=clickbutton onclick='dosomething(this)'> But instead
How to this for combobox?I have long stackpanel which first it has only combobox.And
I have long file with the following list: /drivers/isdn/hardware/eicon/message.c//add_b1() /drivers/media/video/saa7134/saa7134-dvb.c//dvb_init() /sound/pci/ac97/ac97_codec.c//snd_ac97_mixer_build() /drivers/s390/char/tape_34xx.c//tape_34xx_unit_check() (PROBLEM)/drivers/video/sis/init301.c//SiS_GetCRT2Data301() /drivers/scsi/sg.c//sg_ioctl()
Perhaps any of you can help me with this anoying problem. I have long
I have long text . And I'm converting this string to dict. Here is
I have long strings. Like this {{ name = name prodcuer =producer writer =
I have long fortran code that has to be made usable from python. I
This is my code: long currentTime = System.currentTimeMillis(); Date date = new Date(currentTime); //
I have long [] data and i need to convert it to ArrayList<BigInteger> Is
Let's say i have long list of names (about 10 000) stored in MySQL

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.