Skip to content
Snippets Groups Projects
Commit 1f5df605 authored by Andreas Kloeckner's avatar Andreas Kloeckner
Browse files

Add pytools.common_prefix().

parent 865709f5
No related branches found
No related tags found
No related merge requests found
...@@ -575,6 +575,26 @@ def all_roughly_equal(iterable, threshold): ...@@ -575,6 +575,26 @@ def all_roughly_equal(iterable, threshold):
def common_prefix(iterable, empty=None):
it = iter(iterable)
try:
pfx = it.next()
except StopIteration:
return empty
for v in it:
for j in range(len(pfx)):
if pfx[j] != v[j]:
pfx = pfx[:j]
if j == 0:
return pfx
break
return pfx
def decorate(function, list): def decorate(function, list):
return map(lambda x: (x, function(x)), list) return map(lambda x: (x, function(x)), list)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment