Abbreviations, automatic: Difference between revisions
m
→Functional Python: Updated one further primitive
m (→Functional Python: Updated primitives) |
m (→Functional Python: Updated one further primitive) |
||
Line 2,394:
(An optimisation for higher levels of code reuse, faster code development, and easier refactoring. Note that the generic primitives are curried, allowing for more flexible composition):
<lang python>from itertools import (accumulate, chain)
from os.path import expanduser
Line 2,401 ⟶ 2,402:
return next(
len(a[0]) for a in map(
compose(nub)(map_(concat)),
transpose(map(inits,
),▼
) if n == len(a)
)
Line 2,417 ⟶ 2,414:
)))
for i, n in enumerate(
map(compose(abbrevLen)(words), xs)
)▼
):
print (n, ' ', xs[i])
Line 2,462 ⟶ 2,456:
# readFile :: FilePath -> IO String
def readFile(fp):
expanduser(fp), 'r', encoding='utf-8'
|