Browse Source

Add max_match

This function will be used to find eGalax drm device.
pull/2/head
Ali Hatami Tajik 2 years ago
parent
commit
f85227f9f2
  1. 30
      src/scripts/python/util/common.py

30
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]
Loading…
Cancel
Save