[Python] Function like dict.get but returns value of default key instead of default value?

Discussão em 'Python' iniciado por Stack, Março 16, 2025.

  1. Stack

    Stack Membro Participativo

    Let's say

    a = {1:2, 3:4, 5:6}


    Is there a builtin function (maybe something like a.get2(7,5)) that will return a[7], or a[5] if a[7] doesn't exist?

    Such function can be defined easily as a.get(val, a.get(def_key)) but would prefer a builtin solution if exists.

    Continue reading...

Compartilhe esta Página