I have the following list:
bananas = ['7,2,1 : Banana', 'Z : Banana', 'L,D : Banana']
I am would like to use Python's high order functions to derive the following:
[['7', '2', '1'], ['Z'], ['L', 'D']]
I have written this:
bananas_stripped = map(lambda x: [x.split(':')[0]], bananas)
...which produces this:
[['7,2,1 '], ['Z '], ['L,D ']]
I can apply another HOF like so:
test = map(lambda x: x[0].split(','), bananas_stripped)
But I can't figure out how to write it all in one function, i.e. I would like to do it all within bananas_stripped
.
map(lambda x: x.split(':')[0].strip().split(','), bananas)
? – vaultah