小编vik*_*iky的帖子

如何从Python中的大列表中删除曾经使用过的列表中的项目以节省内存?

如果我有一个包含数百万个项目的大型列表,我想迭代它们中的每一个。一旦我使用了该项目,它将永远不会再次使用,那么如何从使用过的列表中删除该项目呢?最好的方法是什么?我知道 numpy 快速且高效,但想知道如何使用普通列表来完成它。

mylst = [item1, item2,............millions of items]
for each_item in mylist:
    #use the item
    #delete the item to free that memory
Run Code Online (Sandbox Code Playgroud)

python loops memory-management python-3.x

0
推荐指数
1
解决办法
1602
查看次数

标签 统计

loops ×1

memory-management ×1

python ×1

python-3.x ×1