Using an extremely long List in Python results in excessive memory usage
扔个三星炸死你
扔个三星炸死你 2017-07-05 10:51:29
0
1
1509

I need to use a List with a length of more than 500,000 in a program, but the result is that the memory usage increases instantly

What method should be used for optimization?

扔个三星炸死你
扔个三星炸死你

reply all(1)
習慣沉默

Does this list have to be stored in memory?

If you are processing them one by one and do not need to store them all in memory, you can write the contents to a disk file first, then open it and use a statement similar to the following:

for item in file('xxx.txt').xreadlines():
    ... # 解析出你的内容,并处理
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template