3 ms·
PEP20 sound amazing, but then when this only way end up being way too verbose/ugly, you are kind of stuck with it. Compare: #python import re m = r
by aexaey 11y ago
PEP20 sound amazing, but then when this only way end up being way too verbose/ugly, you are kind of stuck with it. Compare:
#python
import re
m = re.search('(a.+)(d.+)', 'abcdef')
if m:
print(f"{m.group(1)},{m.group(2)}")
#perl
if('abcdef' =~ /(a.+)(d.+)/){
print "$1,$2";
}
- JoshTriplett 11y agoI don't know why Python re match objects don't support indexing; a __getitem__ method would allow m[1] and m[2] instead (or m['name'] for named groups). That aside, though, I don't consider brevity alone the most critical criteria for a programming language; that way lies APL. Expressiveness, yes, but not at the expense of clarity.