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

Dave Angel davea at davea.name
Sun Dec 1 05:52:08 CET 2013


On Sun, 1 Dec 2013 14:32:38 +1000, Amit Saha <amitsaha.in at gmail.com> 
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:

> >>> mylist = []
> >>> mylist.append(1)

Nothing evil about append.  Many times the list can be built more 
prettily with a list comprehension,  but if you're building it in a 
for loop, append does the job.

-- 
DaveA



More information about the Tutor mailing list