Comment

Comment by ghewgill

The walrus operator allows you to use `elif` there to avoid cascading indentation.

    if m := re.match(pattern1, line):
        do_stuff(m.group(1))
    elif m := re.match(pattern2, line):
        do_other_stuff(m.group(2))
    elif m := re.match(pattern3, line):
        do_things(m.groups())
    else:
        ...
parent ghewgill 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton