1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] python Multidict implementation [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    Please review my implementation of class Multidict

    https://github.com/oraytman/multidict

    class MultiDict(dict):
    def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self._count = 0

    def __setitem__(self, key, value):
    try:
    _ = super().__getitem__(key)
    except KeyError:
    super().__setitem__(key, [value])
    self._count += 1
    else:
    super().__getitem__(key).append(value)
    self._count += 1

    def __delitem__(self, key):
    self._count -= len(self[key])
    _ = super().pop(key)

    def __len__(self):
    return self._count

    def __repr__(self):
    return f"{self.__class__.__name__}({super().__repr__()})"


    Appreciate if you add PR to make it better

    What is the best way to implement method below?

    def __delitem__(self, key):
    self._count -= len(self[key])
    _ = super().pop(key)

    Continue reading...

Compartilhe esta Página