Code

 avatar
unknown
python
2 years ago
493 B
3
Indexable
import re
import functools

files = ["DUT_logcat_A_B.txt", "logcat_C_D.txt", "logcat_1.txt"]
pattern = "("+ ("|".join(["logcat", "DUT_logcat"])) + ")_(\w+)_(\w+)"

exp = re.compile("logcat_[\s]*-[\s]*")

def myMatchingFunction(x):
    res = re.match(pattern, x)
    if res != None:
         values = res.groups()[1:]
         return { values[0] : values[1] }
    return {}

matches = list(map(myMatchingFunction, files))
ans = functools.reduce(lambda x,y : {**x, **y}, matches)
print(ans)




Editor is loading...