set.add() doesn't replace equal element

Chris Angelico rosuav at gmail.com
Fri Dec 30 17:46:45 EST 2022


On Sat, 31 Dec 2022 at 09:29, Ian Pilcher <arequipeno at gmail.com> wrote:
>
> On 12/30/22 15:47, Paul Bryan wrote:
> > What kind of elements are being added to the set? Can you show
> > reproducible sample code?
>
> The objects in question are DHCP leases.  I consider them "equal" if
> the lease address (or IPv6 prefix) is equal, even if the timestamps have
> changed.  That code is not small, but it's easy to demonstrate the
> behavior.

Seems the more logical approach would be to use a dictionary mapping
the lease address/prefix to the timestamp? The part that contributes
to the equality check is the key, and everything else is the value.

ChrisA


More information about the Python-list mailing list