Longest common suffix: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
m →‎{{header|Haskell}}: Reduced slightly with foldr
Hout (talk | contribs)
→‎{{header|Python}}: (replaced `reversed` and a comprehension) with reduce
Line 347: Line 347:


from itertools import takewhile
from itertools import takewhile
from functools import reduce




Line 357: Line 358:
h = cs[0]
h = cs[0]
return all(h == c for c in cs[1:])
return all(h == c for c in cs[1:])

return ''.join(reversed([
def firstCharPrepended(s, cs):
x[0] for x in takewhile(
return cs[0] + s
return reduce(
firstCharPrepended,
takewhile(
p,
p,
zip(*(reversed(x) for x in xs))
zip(*(reversed(x) for x in xs))
)
),
]))
''
)