mapping a statement over all list items

Kevin Christie crispiewm at hotmail.com
Sun Nov 11 10:33:24 CET 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