<br><br><div class="gmail_quote">On Tue, Mar 5, 2013 at 8:06 PM, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 3/5/2013 2:50 PM, Ethan Furman wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I suspect the new behavior would be most useful when you don't know<br>
precisely how large the final list will be: overallocate (possibly by a<br>
large margin), then __exit__ returns the unused portion back to the pool).<br>
</blockquote>
<br></div>
If one counts the items as they are added, it is easy to delete extras.<br>
<br>
ll = [None]*200<br>
for i in range(195):<br>
  ll[i] = i<br>
del ll[195:]<br>
ll[190:]<br>
# [190, 191, 192, 193, 194]<br>
<br>
del ll[ll.index(None):]<br>
would do the same thing and be faster than counting one by one.<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote></div><div><br></div><div>Length hints can lie, so there's a possibility of underallocation. So you need an additional check to use use ll.append instead</div>
<div><br></div>--<br>Philip Jenvey