mapping a statement over all list items

Kevin Christie crispiewm at hotmail.com
Sun Nov 11 04:33:24 EST 2001


Fernando PĂ©rez wrote:

>> Thus if Foo was ['abc-xyz', 'black-blue', '123-987'], the result after
>> mapping to Foo would be:
>> 
>> Foo = [ ['abc', 'xyz'], ['black','blue'], ['123','987'] ]
>> 
> 
> Is this good enough for you (never mind the bizarre prompts, I have my own 
> interpreter)?
> 
> In[1]:= foo=['abc-xyz', 'black-blue', '123-987']
>  
> In[1]:= [x.split('-') for x in foo]
>  
> Out[1]= [['abc', 'xyz'], ['black', 'blue'], ['123', '987']]
> 
> 
> Cheers,
> 
> f

Thanks, that worked great :) I'm still a bit new to Python, but love it 
so far!

Sincerely,
Kevin Christie
Neuroscience Program
University of Illinois at Urbana-Champaign
crispiewm at hotmail.com




More information about the Python-list mailing list