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

  • Home
  • SEARCH
  • 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 6884799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:33:16+00:00 2026-05-27T05:33:16+00:00

I have the for loop code: people = queue.Queue() for person in set(list_): first_name,last_name

  • 0

I have the for loop code:

people = queue.Queue()
for person in set(list_):
    first_name,last_name = re.split(',| | ',person)
    people.put([first_name,last_name])

The list being iterated has 1,000,000+ items, it works, but takes a couple seconds to complete.

What changes can I make to help the processing speed?

Edit: I should add that this is Gevent’s queue library

  • 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-27T05:33:17+00:00Added an answer on May 27, 2026 at 5:33 am

    The question is what is your queue being used for? If it isn’t really necessary for threading purposes (or you can work around the threaded access) in this kind of situation, you want to switch to generators – you can think of them as the Python version of Unix shell pipes. So, your loop would look like:

    def generate_people(list_):
        previous_row = None
        for person in sorted(list_):
            if person == previous_row:
                continue
            first_name,last_name = re.split(',| | ',person)
            yield [first_name,last_name]
            previous_row = person
    

    and you would use this generator like this:

    for first_name, last_name in generate_people():
        print first_name, last_name
    

    This approach avoids what is probably your biggest performance hits – allocating memory to build a queue and a set with 1,000,000+ items on it. This approach works with one pair of strings at a time.

    UPDATE

    Based on more information about how threads play a roll in this, I’d use this solution instead.

    people = queue.Queue()
    previous_row = None
    for person in sorted(list_):
        if person == previous_row:
            continue
        first_name,last_name = re.split(',| | ',person)
        people.put([first_name,last_name])
        previous_row = person
    

    This replaces the set() operation with something that should be more efficient.

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

Sidebar

Related Questions

I have a certain loop occurring several times in various functions in my code.
I have some code which collects points (consed integers) from a loop which looks
i have the following code ..i need to loop through end of the file
I have created some python code which creates an object in a loop, and
I have a following code in a most inner loop of my program struct
I break the code of the for loop without using break like I have
The following code returns the error from the For Each loop. I have similar
I have this code in my every model. Class people def before_validation @attributes.each do
I have a site that people put stuff for sale on. Every month, every
I have seen some very weird for loops when reading other people's code. I

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.