<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 8, 2013 at 6:40 AM, Eli Bendersky <span dir="ltr"><<a href="mailto:eliben@gmail.com" target="_blank">eliben@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="im">On Fri, Mar 8, 2013 at 6:04 AM, Daniel Holth <span dir="ltr"><<a href="mailto:dholth@gmail.com" target="_blank">dholth@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>On Fri, Mar 8, 2013 at 8:35 AM, Antoine Pitrou <<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>> wrote:<br>



> Le Fri, 8 Mar 2013 08:18:07 -0500,<br>
> Daniel Holth <<a href="mailto:dholth@gmail.com" target="_blank">dholth@gmail.com</a>> a écrit :<br>
>><br>
>> I am a fan of the proposal. Imagine you are programming for a<br>
>> memory-constrained system. By telling the list how big it needs to be<br>
>> you can save precious RAM.<br>
><br>
> Is it an actual use case or are you just imagining it? :)<br>
> I'm asking because, unless you are only allocating that list and all<br>
> the objects contained it in it already exist, limiting the list's size<br>
> won't do much for the process' memory occupation.<br>
<br>
</div>It might help if it was a list of integers between -1 and 99 and<br>
1-character strings.</blockquote></div><div><br>That's not what you should use lists for if memory consumption matters. Use <a href="http://docs.python.org/dev/library/array.html" target="_blank">http://docs.python.org/dev/library/array.html</a>, especially if your integers are in such a limited range.<span class=""><font color="#888888"></font></span><br>

</div></div></div></div></blockquote></div><br>>>> sys.getsizeof(list(range(100)))<br>1024<br>>>> sys.getsizeof(array('i', list(range(100))))<br>480<br>>>> sys.getsizeof(array('b', list(range(100))))<br>

180<br><br></div><div class="gmail_extra">This can help you *way* more than playing with growing and shrinking lists.<br><br>Eli<br><br></div><div class="gmail_extra"><br></div></div>