Linked Questions
33 questions linked to/from Delete an element from a dictionary
-1
votes
1
answer
3k
views
How can I remove one element in a json string in Python? [duplicate]
I have this payload:
payload = {
"cluster": "analytics",
"id_pipeline": "123456789",
"schema_compatibility": "backward",
&...
0
votes
2
answers
2k
views
How to delete a value from a dictionary? [duplicate]
How can I delete a value, for example John, out of the dictionary?
data = {'Player': ['John','Steffen'], age: [25,26]}
data.pop("Player","John")
I just can’t find how I can delete a key like Player.
0
votes
2
answers
186
views
How can I delete a dictionary object using python? [duplicate]
I've got a dictionary that I am trying to remove a specific object.
{
"authorizationQualifier": "00",
"testIndicator": " ",
"functionalGroups": [...
-1
votes
2
answers
127
views
How to remove specific element from the dictionary? [duplicate]
How to remove a specific element or data from the dictionary? Suppose I have this dictionary
data = {
'name': 'Instagram',
'follower_count': 346,
'description': 'Social media platform',
...
3011
votes
11
answers
3.1m
views
How can I remove a key from a Python dictionary?
I want to remove a key from a dictionary if it is present. I currently use this code:
if key in my_dict:
del my_dict[key]
Without the if statement, the code will raise KeyError if the key is not ...
1546
votes
23
answers
1.3m
views
How to copy a dictionary and only edit the copy
I set dict2 = dict1. When I edit dict2, the original dict1 also changes. How can I avoid this?
>>> dict1 = {"key1": "value1", "key2": "value2"}
>>...
538
votes
15
answers
616k
views
How to avoid "RuntimeError: dictionary changed size during iteration" error?
Suppose I have a dictionary of lists:
d = {'a': [1], 'b': [1, 2], 'c': [], 'd':[]}
Now I want to remove key-value pairs where the values are empty lists. I tried this code:
for i in d:
if not d[i]...
169
votes
20
answers
199k
views
Efficient way to remove keys with empty strings from a dict
I have a dict and would like to remove all the keys for which there are empty value strings.
metadata = {u'Composite:PreviewImage': u'(Binary data 101973 bytes)',
u'EXIF:CFAPattern2': u''}...
48
votes
5
answers
118k
views
What is the best way to remove a dictionary item by value in python? [duplicate]
I wonder if there is simple way to remove one or more dictionary element(s) from a python dictionary by value.
We have a dictionary called myDict:
myDict = {1:"egg", "Answer":42, 8:14, "foo":42}
and ...
44
votes
2
answers
76k
views
Delete a key and value from an OrderedDict
I am trying to remove a key and value from an OrderedDict but when I use:
dictionary.popitem(key)
it removes the last key and value even when a different key is supplied. Is it possible to remove a ...
9
votes
5
answers
9k
views
Python: how to remove a value from a dict if it exactly matches the key?
Being that the key has multiple values and I want to remove the one that is the same as the key itself? That is, I have a dictionary jumps:
jumps = {'I6': ['H6', 'I6', 'I5'], 'T8' : ['T6', 'S6', 'T8']...
4
votes
3
answers
9k
views
Removing key/value pair from Dictionary in Python
I'm quite a beginner with python.
I'm trying to remove all the 'noone: 0' from this dictionary, so it will look the same as below but without any of the 'noone: 0':
G = {'a': {'b': 10, 'c': 8, 'd': ...
0
votes
6
answers
2k
views
Slicing a list of dictionaries and removing one key
I have a list of dictionaries, like the one below:
l = [ { "a": 10, "b": 4, "c": 6 },
{ "a": 10, "b": 6, "c": 8 },
{ "a": 13, "b": 3, "c": 9 },
{ "a": 12, "b": 5, "c": 3 },
{ "...
1
vote
2
answers
5k
views
Remove key and its value in nested dictionary using python
Looking for a generic solution where I can remove the specific key and its value from dict.
For example, if dict contains the following nested key-value pair:
data={
"set": {
"type": "object", #&...
0
votes
1
answer
8k
views
How do I delete an edge from a graph in Python
I'm reading ThinkComplexity book, I'm new to python, so I have this code:
class Graph(dict):
def __init__(self, vs=[], es=[]):
"""
:param vs: list of vertices/nodes in the graph
...