DEV Community

Cristian Vargas
Cristian Vargas

Posted on

2

Answer: how to use python "get()" for keys deeper than first level of dictionary keys?

You can pass a default value as the second argument to dict.get(), like this:

dict.get('keyB_1', {}).get('keyB_2', {}).get('keyB_3')

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs