内存错误的可能性? [英] Possibility of memory error?

查看:139
本文介绍了内存错误的可能性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

a=raw_input()
prefix_dict = {}
for j in xrange(1,len(a)+1):
    prefix = a[:j]
    prefix_dict[prefix] = len(prefix)
print prefix_dict

以上代码中是否可能发生内存错误?此代码在服务器上运行,该服务器是运行32位Ubuntu(Ubuntu 12.04 LTS)的四核Xeon机器.在少数情况下,其运作正常,而在少数情况下,显示内存错误.仅供参考:我不知道他们正在测试的情况,但输入内容是小写字母.输入大小< = 10,000

Is there any possibility of memory error in the above code? This code is running on a server, the server is a quad core Xeon machines running 32-bit Ubuntu (Ubuntu 12.04 LTS). For few cases its working and for few its showing memory error. FYI: I do not know the cases that they are testing but inputs are lower case alphabets. Size of input <= 10,000

推荐答案

也许一小段代码会有所帮助:

Maybe a smaller piece of code will help:

prefix_dict = { a[:j]:j for j in xrange(1, len(a) + 1) }

这篇关于内存错误的可能性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆