Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

memory error in python

$
0
0
Traceback (most recent call last):File "/run-1341144766-1067082874/solution.py", line 27, in main()File "/run-1341144766-1067082874/solution.py", line 11, in mainif len(s[i:j+1]) > 0:MemoryErrorError in sys.excepthook:Traceback (most recent call last):File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 64, in apport_excepthookfrom apport.fileutils import likely_packaged, get_recent_crashesFile "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in from apport.report import ReportMemoryErrorOriginal exception was:Traceback (most recent call last):File "/run-1341144766-1067082874/solution.py", line 27, in main()File "/run-1341144766-1067082874/solution.py", line 11, in mainif len(s[i:j+1]) > 0:MemoryError

The above errors appeared when I tried to run the following program. Can someone explain what is a memory error, and how to overcome this problem? . The program takes strings as input and finds all possible sub strings and creates a set(in a lexicographical order) out of it and it should print the value at the respective index asked by the user otherwise it should print 'Invalid'

def main():    no_str = int(raw_input())    sub_strings= []    for k in xrange(0,no_str):        s = raw_input()        a=len(s)        for i in xrange(0, a):            for j in xrange(0, a):                if j >= i:                    if len(s[i:j+1]) > 0:                        sub_strings.append(s[i:j+1])    sub_strings = list(set(sub_strings))    sub_strings.sort()    queries= int(raw_input())    resul = []    for i in xrange(0,queries):        resul.append(int(raw_input()))    for p in resul:        try:            print sub_strings[p-1]        except IndexError:            print 'INVALID'if __name__ == "__main__":   main()

Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>