3 ms·
Nice way in without walrus m = re.match(p1, line) if m: return m.group(1) m = re.match(p2, line) if m: return m.group(2) m
by wodenokoto 7y ago
Nice way in without walrus
m = re.match(p1, line)
if m:
return m.group(1)
m = re.match(p2, line)
if m:
return m.group(2)
m = re.match(p3, line)
...
With walrus:
if m := re.match(p1, line):
return m.group(1)
elif m := re.match(p2, line):
return m.group(2)
elif m := re.match(p3, line):
The example would have been better if it didn't have the return, but just a value assign or a function call.