I think my most common use case is with dictionary lookups.
if (val := dct.get(key)) is not None:
# do something with val
I’ve also found some cases where the walrus is useful in something like a list comprehension. I suppose expanding on the above example, you you make one that looks up several keys in a dict and gives you their corresponding values where available.
vals = [val for key in (key1, key2, key3) if (val := dct.get(key)) is not None]
I think my most common use case is with dictionary lookups.
I’ve also found some cases where the walrus is useful in something like a list comprehension. I suppose expanding on the above example, you you make one that looks up several keys in a dict and gives you their corresponding values where available.