[Python-ideas] Fwd: Extremely weird itertools.permutations
Oscar Benjamin
oscar.j.benjamin at gmail.com
Mon Oct 14 01:32:34 CEST 2013
On 14 October 2013 00:23, Tim Peters <tim.peters at gmail.com> wrote:
> [Tim]
>>> 2. Making "equality" pluggable. Your later algorithm bought "find
>>> equivalence classes" speed for hashable elements by using a dict, but
>>> a dict's notion of equality can't be changed. So, make equality
>>> pluggable, and that startup-time speed advantage vanishes for all but
>>> operator.__eq__'s idea of equality.
>
> [Oscar Benjamin]
>> It sounds like you want Antoine's TransformDict:
>> http://www.python.org/dev/peps/pep-0455/
>
> Not really in this case - I want a two-argument function ("are A and B
> equal?"). Not all plausible cases of that can be mapped to a
> canonical hashable key. For example, consider permutations of a list
> of lists, where the user doesn't want int and float elements of the
> lists to be considered equal when they happen to have the same value.
> Is that a stretch? Oh ya ;-)
Will this do?
d = TransformDict(lambda x: (type(x), x))
Oscar
More information about the Python-ideas
mailing list