Jump to content

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, map_(concatxs))
),
transpose(
map(inits, xs)
)
) if n == len(a)
)
Line 2,417 ⟶ 2,414:
)))
for i, n in enumerate(
map(compose(abbrevLen)(words), xs)
compose(abbrevLen)(words),
xs
)
):
print (n, ' ', xs[i])
Line 2,462 ⟶ 2,456:
# readFile :: FilePath -> IO String
def readFile(fp):
returnwith open(fp).read()
expanduser(fp), 'r', encoding='utf-8'
) as )f:
return f.read(),
 
 
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.