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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:51:02+00:00 2026-06-08T04:51:02+00:00

def suffix(stng): list = [] length = len(stng) for i in range(length): x =

  • 0
def suffix(stng):
    list = []
    length = len(stng)
    for i in range(length):
         x = stng[i:length]   ## This gives a Memory Error..See below
         list.append(x)
    return list

This piece of code is a part of my solution of a problem on interviewstreet.com but when i submit it i get a Memory error…i want to know how to correct it?

This is the traceback:

Original exception was:
Traceback (most recent call last):
File "/run-1342184337-542152202/solution.py", line 35, in
listofsuffix=suffix(var)
File "/run-1342184337-542152202/solution.py", line 13, in suffix
x=stng[i:length]
MemoryError
  • 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-08T04:51:03+00:00Added an answer on June 8, 2026 at 4:51 am

    A MemoryError means you have consumed all your RAM. You are creating a list containing all trailing parts of an original string. If your original string is too long, you will consume a lot of memory.

    One possibility is to use a generator to produce the suffixes one at a time instead of creating a list of all of them:

    def suffixes(stng):
        for i in xrange(len(stng)):
             yield stng[i:]
    

    If the caller of suffixes simply iterates over the result, you don’t even have to change the caller. If you truly needed an explicit list, then you’ll need a different solution.

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

Sidebar

Related Questions

def common_elements(list1, list2): Return a list containing the elements which are in both list1
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
def digits(n): res = [] while n > 0: res.append(n % 10) n /=
def clean_title(self): title = self.cleaned_data['title'] if len(title) < 5: raise forms.ValidationError(Please write more in
def test4(request): logging.debug(request) logging.debug(request.META['HTTP_REFERER']) return render_to_response('test2/test4.html', context_instance=RequestContext(request)) In the above code can request be
def register(request): flag = True possible = '0123456789abcdefghijklmnopqrstuvwxyz' token = '' length = 10
def remove_section(alist, start, end): Return a copy of alist removing the section from start
def countSubStringMatchRecursive(target,key): Counts how many times key is in string(string,key) x=find(target,key) print x return

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.