[Tutor] Populating a list

Steven D'Aprano steve at pearwood.info
Mon Oct 22 05:31:12 CEST 2012

On Mon, Oct 22, 2012 at 06:44:51AM +0500, Saad Javed wrote:
> My program downloads multiple entry values from the net. I'm trying to
> combine them in a list in a particular sequence.
> l = []
[snip rest of code]
> l.append([e, f, g])
> The problem I'm facing is that the values don't combine into a single list
> ("l"). It keeps printing multiple lists with three values e, f, g as the
> xml tree is parsed.

Of course it does. You tell it to: you are appending a new list with 
three entries, [e, f, g].

What you should do is either append each item separately:


or use the extend method:

l.extend([e, f, g])

which is a short-cut for three individual appends.


More information about the Tutor mailing list