this post was submitted on 26 Jul 2025
73 points (98.7% liked)

Python

7340 readers
61 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] tunetardis@piefed.ca 2 points 6 days ago

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]