Anonymous user
Longest common prefix: Difference between revisions
→Python: Functional: revert to original version because the other version may have bad complexity; but use min & max instead of sort
(→Python: Functional: revert to original version because the other version may have bad complexity; but use min & max instead of sort) |
|||
Line 58:
===Python: Functional===
To see if all the n'th characters are the same I compare the min and max characters in the lambda function.
<lang python>from itertools import takewhile
def lcp(*s):
return ''.join(
assert lcp("interspecies","interstelar","interstate") == "inters"
|