Liste des Groupes | Revenir à cl python |
Loris wrote:
>
"Yes, I was mistakenly thinking that the popping the element would leave
me with the dict minus the popped key-value pair. Seem like there is no
such function."
>
Others have tried to explain and pointed out you can del and then use the
changed dict.
>
But consider the odd concept of writing your own trivial function.
>
def remaining(adict, anitem):
_ = adict.pop(anitem)
# alternatively duse del on dict and item
return adict
>
>{'first': 1, 'third': 3}remaining({"first": 1, "second": 2, "third": 3}, "second")
>
>
Or do you want to be able to call it as in dict.remaining(key) by
subclassing your own variant of dict and adding a similar method?
Les messages affichés proviennent d'usenet.