列表列表与Python中单个列表的内存使用情况 [英] List of lists vs single list memory usage in Python

查看:151
本文介绍了列表列表与Python中单个列表的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要整理一堆数字,并考虑按照它们的语义将它们组织在列表中.

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

将数据整理为以下形式的内存使用方面的开销是多少? 列表列表与python中的单个平面列表?

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

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

推荐答案

只有很少的开销.以最有意义的方式来组织数据,在真正成为问题之前,不必担心性能.在这种情况下,它极不可能成为问题.

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.

这篇关于列表列表与Python中单个列表的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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