Given a list of pathnames, returns the longest common leading component

def _commonprefix(m):
    "Given a list of pathnames, returns the longest common leading component"
    if not m:
        return ''
    prefix = m[0]
    for item in m:
        for i in range(len(prefix)):
            if prefix[:i+1] != item[:i+1]:
                prefix = prefix[:i]
                if i == 0:
                    return ''
                break
    return prefix