Substring/Top and tail: Difference between revisions
Content added Content deleted
m (Reverted an inadvertent edit) |
(→{{header|Python}}: (added other two example strings)) |
||
Line 1,350:
def main():
ap([
['knights', 'socks', 'brooms']
)▼
)
▲ ))
):
print(xs)
Line 1,378 ⟶ 1,379:
), fs, []
)
# chunksOf :: Int -> [a] -> [[a]]
def chunksOf(n):
return lambda xs: reduce(
lambda a, i: a + [xs[i:n + i]],
range(0, len(xs), n), []
) if 0 < n else []
Line 1,383 ⟶ 1,392:
def compose(g):
return lambda f: lambda x: g(f(x))
# transpose :: [[a]] -> [[a]]
def transpose(xs):
return list(map(list, zip(*xs)))
Line 1,388 ⟶ 1,402:
main()</lang>
{{Out}}
<pre>['nights', 'knight', 'night']
['ocks', 'sock', 'ock']
['rooms', 'broom', 'room']</pre>
=={{header|Racket}}==
|