mapping a statement over all list items

Kevin Christie crispiewm at hotmail.com
Sun Nov 11 04:10:15 EST 2001


Hello all!

   I have list Foo, of strings. Each string has a special character '-' 
within the string. What I want is for Python to split each string list 
item by '-' and assign the resulting lists to the original list item.
Basically, I want to apply:

Foo[x] = Foo[x].split('-')

over all items x in Foo, in one clean statement.

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'] ]

It seems as if there should be a way to map the function over all items 
in one elegant statement, but map() requires an explicit function, not a 
python statement, and I'm not sure if what I want is possibly through 
the use of lambda forms. Any help?

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




More information about the Python-list mailing list