Re: Popping key causes dict derived from object to revert to object

Liste des GroupesRevenir à cl python 
Sujet : Re: Popping key causes dict derived from object to revert to object
De : loris.bennett (at) *nospam* fu-berlin.de (Loris Bennett)
Groupes : comp.lang.python
Date : 25. Mar 2024, 16:58:39
Autres entêtes
Organisation : FUB-IT (ex-ZEDAT), Freie Universität Berlin
Message-ID : <87le66pdcw.fsf@zedat.fu-berlin.de>
References : 1 2 3 4 5 6 7
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
"Michael F. Stemper" <michael.stemper@gmail.com> writes:

On 25/03/2024 01.56, Loris Bennett wrote:
Grant Edwards <grant.b.edwards@gmail.com> writes:
 
On 2024-03-22, Loris Bennett via Python-list <python-list@python.org> wrote:
>
Yes, I was mistakenly thinking that the popping the element would
leave me with the dict minus the popped key-value pair.
>
It does.
Indeed, but I was thinking in the context of
   dict_list = [d.pop('a') for d in dict_list]
and incorrectly expecting to get a list of 'd' without key 'a',
instead
of a list of the 'd['a]'.
I apologize if this has already been mentioned in this thread, but are
you aware of "d.keys()" and "d.values"?
>
 >>> d = {}
 >>> d['do'] = 'a deer, a female deer'
 >>> d['re'] = 'a drop of golden sunshine'
 >>> d['mi'] = 'a name I call myself'
 >>> d['fa'] = 'a long, long way to run'
 >>> d.keys()
 ['fa', 'mi', 'do', 're']
 >>> d.values()
 ['a long, long way to run', 'a name I call myself', 'a deer, a female deer', 'a drop of golden sunshine']
 >>>

Yes, I am, thank you.  However, I didn't want either the keys or the
values.  Instead I wanted to remove a key within a list comprehension.

Cheers,

Loris

PS: "a drop of golden *sun*" - rhymes with "a long, long way to run"


--
This signature is currently under constuction.

Date Sujet#  Auteur
21 Mar 24 * Popping key causes dict derived from object to revert to object14Loris Bennett
21 Mar 24 +- Re: Popping key causes dict derived from object to revert to object1dieter.maurer
21 Mar 24 `* Re: Popping key causes dict derived from object to revert to object12Mark Bourne
22 Mar 24  `* Re: Popping key causes dict derived from object to revert to object11Loris Bennett
22 Mar 24   +* Re: Popping key causes dict derived from object to revert to object7Grant Edwards
25 Mar 24   i`* Re: Popping key causes dict derived from object to revert to object6Loris Bennett
25 Mar 24   i +* Re: Popping key causes dict derived from object to revert to object3Michael F. Stemper
25 Mar 24   i i`* Re: Popping key causes dict derived from object to revert to object2Loris Bennett
25 Mar 24   i i `- Re: Popping key causes dict derived from object to revert to object1Jon Ribbens
25 Mar 24   i +- Re: Popping key causes dict derived from object to revert to object1Grant Edwards
25 Mar 24   i `- Re: Popping key causes dict derived from object to revert to object1<avi.e.gross
22 Mar 24   +- Re: Popping key causes dict derived from object to revert to object1<avi.e.gross
25 Mar 24   +- Re: Popping key causes dict derived from object to revert to object1Loris Bennett
25 Mar 24   `- Re: Popping key causes dict derived from object to revert to object1<avi.e.gross

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal