dict.get_deep()

Marco Sulla Marco.Sulla.Python at gmail.com
Sun Apr 3 15:14:13 EDT 2022


On Sun, 3 Apr 2022 at 16:59, Kirill Ratkin via Python-list
<python-list at python.org> wrote:
>
> Hi Marco.
>
> Recently I met same issue. A service I intergated with was documented
> badly and sent ... unpredictable jsons.
>
> And pattern matching helped me in first solution. (later I switched to
> Pydantic models)
>
> For your example I'd make match rule for key path you need. For example:
>
>
> data = {"users": [{"address": {"street": "Baker"}}]}
>
> match data:
>      case {"users": [{"address": {"street": street}}]}:
>          print(f"street: {street}")
>
>      case _:
>          print("unsupported message structure")

Hi. I think your solution is very brilliant, but I'm a bit allergic to
pattern matching... :D Maybe it's me, but I found it really strange
and "magical".


More information about the Python-list mailing list