Skip to content

Instantly share code, notes, and snippets.

@bockor
Created June 14, 2025 08:52
Show Gist options
  • Save bockor/f3b450244ca72330f97ca1ed72da18e5 to your computer and use it in GitHub Desktop.
Save bockor/f3b450244ca72330f97ca1ed72da18e5 to your computer and use it in GitHub Desktop.
python dictionary nested get
"""
The walrus operator “:=” is an operator used to evaluate, assign, and return value from a single statement in Python.
It was introduced in Python 3.8
"""
sss = {'color': 'red', 'size': 'l', 'clips': {'number': 6, 'material': 'metal'}}
if value := sss.get("clips", {}).get("number"):
print(f"Number of clips: {value}")
"""
Number of clips: 6
"""
if value := sss.get("clips", {}).get("numberxxx"):
print(f"Number of clips: {value}")
"""
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment