Created
July 4, 2012 22:43
-
-
Save niwinz/3049916 to your computer and use it in GitHub Desktop.
kata: make list of list as plain list of elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#from functools import reduce # uncomment if python3+ is used | |
lmb = lambda x, y: x+reduce(lmb, y, []) if isinstance(y, list) else x + [y] | |
reduce(lmb,[1,['a','b'],2,[[1,2, [3]]],'c'], []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
m = [1, ['a', 'b'], 2, [ [ 1, 2, [3]]], 'c'] | |
def myreduce(x, y): | |
if isinstance(y, list): return x + functools.reduce(myreduce, y, []) | |
else: return x+[y] | |
functools.reduce(myreduce, m, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment