[Python-Dev] Add a "transformdict" to collections

Joao S. O. Bueno jsbueno at python.org.br
Wed Sep 11 04:25:03 CEST 2013


On 10 September 2013 18:46, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Tue, 10 Sep 2013 18:44:20 -0300
> "Joao S. O. Bueno" <jsbueno at python.org.br> wrote:
>> On 10 September 2013 18:06, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> > On Tue, 10 Sep 2013 17:38:26 -0300
>> > "Joao S. O. Bueno" <jsbueno at python.org.br> wrote:
>> >> On 10 September 2013 16:08, Paul Moore <p.f.moore at gmail.com> wrote:
>> >> > If you provide "retain the last", I can't see any obvious way of
>> >> > implementing "retain the first" in application code without in effect
>> >> > reimplementing the class.
>> >>
>> >> Which reminds one - this class should obviously have a method for
>> >> retrivieng the original key value, given a matching key -
>> >>
>> >> d.canonical('foo') -> 'Foo'
>> >
>> > I don't know. Is there any use case?
>> > (sure, it is trivially implemented)
>>
>>
>> Well, I'd expect it to simply be there. I had not thought of
>> other usecases for the transformdict itself -
>
> Well, it is not here for dict, set, etc.

For the simple motive that once you retrieve or find that an
element is contained in one of these classes, you already
have the canonical key. :-)

>
>> For example, in latim languages it is common to want
>> accented letters to match their unaccented counterparts
>> - pick my own first name "João" - if I'd use a transform to strip
>> the diactriticals, and have an user input "joao" - it would match,
>> as intended - but I would not be able to retrieve the accented version
>> without re-implementing the class behavior.
>
> Interesting example, thanks.
>
> Regards
>
> Antoine.
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/jsbueno%40python.org.br


More information about the Python-Dev mailing list