When deleting a key from a dictionary, I use:
if \'key\' in my_dict:
del my_dict[\'key\']
Is there a one line way of doing this?
this will change
my_dict
in place (mutable)
my_dict.pop('key', None)
generate a new dict (immutable)
dic1 = {
"x":1,
"y": 2,
"z": 3
}
def func1(item):
return item[0]!= "x" and item[0] != "y"
print(
dict(
filter(
lambda item: item[0] != "x" and item[0] != "y",
dic1.items()
)
)
)