Appending to []

Prasad, Ramit ramit.prasad at jpmorgan.com
Wed Apr 25 14:44:34 EDT 2012


> >> Then nested calls like
> >>
> >> a = [].append('x').append('y').append('z')
> 
> Sequential appends are nearly always done within a loop.

If not in a loop and you have multiple things already in an
iterable (or create the iterable inline) you can use extend

a= []
a.extend( [ 'x, 'y, 'z' ] ) 

Or if creating a new list just populate it inline.

a= [ 'x', 'y', 'z',]


> 
> >> would be possible with a containing the resulting list
> >>
> >> ['x', 'y', 'z'].

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  



More information about the Python-list mailing list