Comment

Comment by pansa2

The walrus operator hardly changes that example at all:

    if m := re.match(pattern1, line):
        do_stuff(m.group(1))
    else:
        if m := re.match(pattern2, line):
            do_other_stuff(m.group(2))
        else:
            if m := re.match(pattern3, line):
                do_things(m.groups())
            else:
                m = ...
I've found `:=` useful in the headers of `while` loops, but that's about it. The complexity that walrus adds to the language far outweighs its usefulness.
parent pansa2 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton