A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-September/128540.html below:

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

[Python-Dev] Add a "transformdict" to collections [Python-Dev] Add a "transformdict" to collectionsMRAB python at mrabarnett.plus.com
Tue Sep 10 21:59:56 CEST 2013
On 10/09/2013 20:08, Paul Moore wrote:
> On 10 September 2013 19:31, Antoine Pitrou <solipsis at pitrou.net> wrote:
>>> I think it would be a flaw to have this detail implementation-defined.
>>> This would be like saying that it is implementation-defined which
>>> of A,B,C is returned from "A and B and C" if all are true.
>>
>> Ok, it seems everyone (except me :-)) agrees that it should return the
>> first key value, so that's how it will be.
>
> If you retain the first key value, it's easy enough for the
> application to implement "retain the last" semantics:
>
> try:
>      del d[k]
> finally:
>      d[k] = v
>
That would raise a KeyError is the key was missing. A better way is:

d.pop(k, None)
d[k] = v

> 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.
>
"Retain the first" does feel more natural to me.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4