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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:40:28+00:00 2026-06-01T14:40:28+00:00

I keep having problems with programs in Python (I’m a complete newb) where it

  • 0

I keep having problems with programs in Python (I’m a complete newb) where it doesn’t store the data from a computation and does it over and over again when I feel like it should have saved it. How can I make Python save the answer so it doesn’t compute the program over and over?

ex:

import prime
def g(x):
    i=0
    while i<len(prime.sieve(x)):
        print str(prime.sieve(x)[i])+' is prime'
        i=i+1

Here’s the “prime” module in case someone wants to compile this:

def sieve(max):
    #Takes in a number, and returns all primes between 2 and that number

    #Start with all of the numbers
    primes = range(2,max+1)
    #Start running through each number 
    for i in primes:
            #Start with double the number, and
            j = 2
            #remove all multiples
            while i * j <= primes[-1]:
                    #As long as the current multiple of the number
                    #is less than than the last element in the list
                    #If the multiple is in the list, take it out
                    if i * j in primes:
                            primes.remove(i*j)
                    j=j+1
    return primes

Anyway, the first bit of code computes the list “prime.sieve(x)” over and over, and I want to save it for reference when printing.

Thanks!

rofls

  • 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-01T14:40:29+00:00Added an answer on June 1, 2026 at 2:40 pm
    saved_sieve_map = {}
    def saved_sieve(x):
      if x not in saved_sieve_map:
        saved_sieve_map[x] = sieve(x)
      return saved_sieve_map[x]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a C program but I keep having problems with my array of
I keep having an error when running my web application. The error does not
We keep having some customers getting a warning from AVG Antivirus about our application.
I keep having problems deciding how I should create my classes internally. Initially I
I'm having problems resolving sub-dependencies from a third-party package. I'm a bit of a
I'm having a problem with my looping over a vector, and deleting values from
I keep getting this error with HG (Mercurial), it seems like it's having a
I'm having trouble getting my validation to act correctly. I keep getting the error
I am having issues with my software. In my piano software if I keep
I've recently started having trouble logging into my site using Facebook. I keep seeing

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.