You are about to erase the element of dict
from Python.
I know how to erase it with dict.pop()
pop()
returns elements that are deleted, right?
I'd like to get the disc with the elements removed back.
The function I'm using right now is
myremove (original, result, key)
I'm getting two dicts as a factor.
Result = myremove(original, key)
Is there a way to make it more Python?
del[key] also clears the element.
However, deld
Since the element d
is removed from the original dict, please write the following when you receive a new dict while preserving the new original dict.
def removekey(d, key):
r = copy d to dict(d) #r
Remove key from del [key] #r (original d is preserved)
Dict return with the key removed
The dict() constructor written in this function proceeds a shallow copy. To make a deep copy
© 2024 OneMinuteCode. All rights reserved.