• How would you name this dictionary?

    From bagratte@live.com@3:633/280.2 to All on Mon Jan 22 06:39:56 2024
    class NameMe(dict):
    def __missing__(self, key):
    return key


    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)
  • From Cameron Simpson@3:633/280.2 to All on Mon Jan 22 11:09:45 2024
    On 21Jan2024 23:39, bagratte@live.com <bagratte@live.com> wrote:
    class NameMe(dict):
    def __missing__(self, key):
    return key

    I would need to know more about what it might be used for. What larger
    problem led you to writing a `dict` subclass with this particular `__missing__` implementation?

    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)
  • From Stefan Ram@3:633/280.2 to All on Mon Jan 22 18:16:51 2024
    Cameron Simpson <cs@cskk.id.au> writes:
    I would need to know more about what it might be used for. What larger >problem led you to writing a `dict` subclass with this particular >`__missing__` implementation?

    The Python Library Reference (Release 3.13.0a0) contains:

    class Default(dict):
    |... def __missing__(self, key):
    |... return key

    . Otherwise, I personally might think of:

    class DefaultsToKey( dict ):
    |... def __missing__( self, key ):
    |... return key

    .


    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: Stefan Ram (3:633/280.2@fidonet)