List of lists vs single list memory usage in Python

我与影子孤独终老i 提交于 2020-01-06 06:37:13

问题


I have a bunch of numbers that I have to organize and am thinking of organizing in lists them by their semantic meaning.

What is the overhead in terms of memory usage of organizing data as a list of lists versus a single flat list in python?

I.e.

  • [[x1,y1,v1],[x2,y2,v2], ... , [xn,yn,vn]]
  • [x1,y1,v1,x2,y2,v2, ... , xn,yn,vn]

回答1:


There would be very, very little overhead. Organize your data in whichever way makes the most semantic sense, and don't worry about performance until it's actually a problem. In this case, it's highly unlikely that it would ever become an issue.



来源:https://stackoverflow.com/questions/31953873/list-of-lists-vs-single-list-memory-usage-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!