Insert item before each element of a list

Agon Hajdari agonh at freenet.de
Mon Oct 8 17:39:26 EDT 2012


On 10/08/2012 11:15 PM, Prasad, Ramit wrote:
> 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.  
> 

I think he wanted to have a 'plain' list
a = [0, 1, 0, 2, 0, 3]
and not
a = [(0, 1), (0, 2), (0, 3)]



More information about the Python-list mailing list