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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:14:29+00:00 2026-06-04T08:14:29+00:00

I am new python programmer,what I have understood so far,yield keyword returns an object

  • 0

I am new python programmer,what I have understood so far,”yield” keyword returns an object in lieu of that the generator function returns only the generator object.

so if I have a list which contains 10K items,how I can make smart,pythonic solution without appending values in a list and make it large.

That means,I am appending some values to a list and finally a large list is created like below:

def example():
    final_list = []
    for i in range(0,10000):
        final_list.append(i)
    return final_list

This is just an example,not a real problem,I used range() just for generating loop nothing else,in my real problem,there are no sequential data,it will be random strings,and the findla list will contain 10K string.
so how can I get all the values without appending to a list in an efficient pythonic manner.

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-06-04T08:14:30+00:00Added an answer on June 4, 2026 at 8:14 am

    You said:

    I am getting some string after crawling a web page and appending those
    string to a list,as the crawler geting large data,the list is getting
    bigger,finally when I want to iterate the list,its time and memory
    consuming

    So:

    # generator function to crawl web pages
    def crawler():
        while iStillHaveWebPagesToCrawl():
            someStrings = getSomeStringsFromAWebPage()
            for aString in someStrings:
                yield aString
    
    def oneStringAtATime():
        for aString in crawler():
            doSomethingWith( aString )
    

    When you call oneStringAtATime(), it sets up the generator function called crawler(); each time crawler() executes yield, the loop in oneStringAtATime() iterates once with that string. When crawler() runs out of web pages and exits the function, the oneStringAtATime() loop exits.

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

Sidebar

Related Questions

I'm a new Python programmer who is making the leap from 2.6.4 to 3.1.1.
I'm a new Python programmer who is having a little trouble using 'self' in
I am a bit new to Python, but an experienced programmer. I am writing
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I'm new to python and have hit a problem with an SQL query I'm
I am new to Python and Numpy, and I am facing a problem, that
I am new to python and graphics but have programmed before. According to http://en.wikipedia.org/wiki/Transformation_matrix#Rotation
I have a background in python and I'm looking for a new language. I
Suppose a programmer has the following problem: he wants to start a new python
I am new to Python and currently have to write a python program/script to

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.