[Python-ideas] [Python-Dev] hello, new dict addition for new eve ?

Robert Kern robert.kern at gmail.com
Tue Jan 3 21:57:25 CET 2012

On 1/3/12 8:50 PM, Devin Jeanpierre wrote:
>> The values are unrestricted Python objects. They do not have to be hashable
>> or sortable. The set operations you describe would have to be require one or
>> both (or else do something algorithmically horrendous).
> He only describes<, which can be implemented in linear time as:
>      def __lt__(self, d2):
>          if not isinstance(d2, dict):
>              return NotImplemented
>          return all(key in d2 and d2[key] == value for key, value in
> self.items())

Actually, this implements __le__. For __lt__, you need to exclude the case where 
they are exactly equal.

You're right though that it wouldn't be algorithmically horrendous to do this.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-ideas mailing list