MCPcopy Index your code
hub / github.com/RustPython/RustPython / commonprefix

Function commonprefix

Lib/genericpath.py:105–119  ·  view source on GitHub ↗

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

(m)

Source from the content-addressed store, hash-verified

103
104# Return the longest prefix of all list elements.
105def commonprefix(m):
106 "Given a list of pathnames, returns the longest common leading component"
107 if not m: return ''
108 # Some people pass in a list of pathname parts to operate in an OS-agnostic
109 # fashion; don't try to translate in that case as that's an abuse of the
110 # API and they are already doing what they need to be OS-agnostic and so
111 # they most likely won't be using an os.PathLike object in the sublists.
112 if not isinstance(m[0], (list, tuple)):
113 m = tuple(map(os.fspath, m))
114 s1 = min(m)
115 s2 = max(m)
116 for i, c in enumerate(s1):
117 if c != s2[i]:
118 return s1[:i]
119 return s1
120
121# Are two stat buffers (obtained from stat, fstat or lstat)
122# describing the same file?

Callers 3

_common_shorten_reprFunction · 0.90
relpathFunction · 0.85
test_commonprefixMethod · 0.85

Calls 4

isinstanceFunction · 0.85
minFunction · 0.85
maxFunction · 0.85
enumerateFunction · 0.85

Tested by 1

test_commonprefixMethod · 0.68