Abbreviations, automatic: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Added a variant (functional composition))
(→‎Python Functional: (some tidying of main function))
Line 1,587: Line 1,587:
return next(
return next(
len(a[0]) for a in map(
len(a[0]) for a in map(
lambda x: nub(map(lambda y: ''.join(y), x)),
compose(nub)(_map(concat)),
transpose(map(inits, xs))
transpose(map(inits, xs))
) if n == len(a)
) if n == len(a)
Line 1,608: Line 1,608:
def compose(g):
def compose(g):
return lambda f: lambda x: g(f(x))
return lambda f: lambda x: g(f(x))


# concat :: [String] -> String
def concat(xs):
return ''.join(xs)




Line 1,620: Line 1,625:
def lines(s):
def lines(s):
return s.splitlines()
return s.splitlines()


# map :: (a -> b) -> [a] -> [b]
def _map(f):
return lambda xs: list(map(f, xs))