[Python-ideas] Fwd: Extremely weird itertools.permutations
Oscar Benjamin
oscar.j.benjamin at gmail.com
Mon Oct 14 01:55:29 CEST 2013
On 14 October 2013 00:44, Tim Peters <tim.peters at gmail.com> wrote:
> [Oscar Benjamin]
>> Will this do?
>> d = TransformDict(lambda x: (type(x), x))
>
> No. In the example I gave, *lists* will be passed as x (it was a list
> of lists: the lists are the elements of the permutations, and they
> happen to have internal structure of their own). So the `type(x)`
> there is useless (it will always be the list type), while the lists
> themselves would still be compared by operator.__eq__.
>
> Not to mention that the constructed tuple isn't hashable anyway (x is
> a list), so can't be used by TransformDict.
>
> So that idea doesn't work several times over ;-)
Damn, you're right. I obviously didn't think that one through hard
enough. Okay how about this?
d = TransformDict(lambda x: (tuple(map(type, x)), tuple(x)))
Oscar
More information about the Python-ideas
mailing list