[Tutor] Alternatives to append() for "growing" a list
Amit Saha
amitsaha.in at gmail.com
Sun Dec 1 05:32:38 CET 2013
Hello,
I was told by someone (as a comment) that a code snippet such as this
"would make Pythonistas talk my ear off about how evil the append()"
function is:
>>> mylist = []
>>> mylist.append(1)
# a number of times over
I have some ideas that on an append() the list's internal size
increases (doubled?) since CPython over-allocates memory, and such.
So, the question is: what is the alternative to growing a list when I
have no idea what items or how many may be there?
Thanks,
Amit.
--
http://echorand.me
More information about the Tutor
mailing list