diff --git a/src/scripts/python/util/common.py b/src/scripts/python/util/common.py new file mode 100644 index 0000000..a66bb6f --- /dev/null +++ b/src/scripts/python/util/common.py @@ -0,0 +1,30 @@ +"""Common Utilities""" + +def max_match(a: str, b: str) -> str: + """Maximum matching of intersection of pair of string + + This function will return the intersection of two strings from the start. + + Example: + >>> a = "/sys/devices/folan/bahman" + >>> b = "/sys/devices/fol/bahman" + >>> max_match(a,b) + '/sys/dedices/fol' + + Args: + a (str): firsrt string + b (str): second string + + Returns: + str: intersection of two strings + """ + i = 0 + + if len(b) < len(a): + a, b = b, a + + for c in a: + if b[i] == c: + i += 1 + else: + return a[0:i]