[Tutor] Alternatives to append() for "growing" a list

Amit Saha amitsaha.in at gmail.com
Sun Dec 8 07:10:45 CET 2013


On Tue, Dec 3, 2013 at 6:32 AM, Danny Yoo <dyoo at hashcollision.org> wrote:
>>
>> 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:
>>
>
>
> I think this thread demonstrates: we don't need an excuse to talk your ears
> off.  :P
>

hehe, indeed.

> Using append() is fine.
>
> If anything, the comment might be referring to an issue with appending
> strings in a naive way.  But without further information, can't say for
> sure.  If you can get more information about what your friend was talking
> about, that would be helpful.

It didn't have to do with strings. It was a basic example of using
append() which is to start with an empty list and and then build it
incrementally:

>>> l = [ ]
>>> l.append(1)
# append more

But yeah, I think that bit of "talking my ears off" is now no more
valid and I have written a good rebuttal to the comment :)


Best,
Amit.

-- 
http://echorand.me


More information about the Tutor mailing list