Insert item before each element of a list

Prasad, Ramit ramit.prasad at jpmorgan.com
Mon Oct 8 17:15:27 EDT 2012


Agon Hajdari wrote:
> Sent: Monday, October 08, 2012 3:12 PM
> To: python-list at python.org
> Subject: Re: Insert item before each element of a list
> 
> On 10/08/2012 09:45 PM, Chris Kaynor wrote:
> > [('insertme', i) for i in x]
> 
> This is not enough, you have to merge it afterwards.

Why do you say that? It seems to work just fine for me.

>>> x
[0, 1, 2, 3, 4]
>>> [('insertme', i) for i in x]
[('insertme', 0), ('insertme', 1), ('insertme', 2), ('insertme', 3), ('insertme', 4)]

> 
> y = [item for tup in y for item in tup]
> 

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