Linked Questions

-1 votes
1 answer
3k views

I have this payload: payload = { "cluster": "analytics", "id_pipeline": "123456789", "schema_compatibility": "backward", &...
Nakano's user avatar
  • 47
0 votes
2 answers
2k views

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.
Sascha Steger's user avatar
0 votes
2 answers
186 views

I've got a dictionary that I am trying to remove a specific object. { "authorizationQualifier": "00", "testIndicator": " ", "functionalGroups": [...
sal's user avatar
  • 74
-1 votes
2 answers
127 views

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', ...
Rushi Jaiswal's user avatar
3011 votes
11 answers
3.1m views

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 ...
Tony's user avatar
  • 38.7k
1546 votes
23 answers
1.3m views

I set dict2 = dict1. When I edit dict2, the original dict1 also changes. How can I avoid this? >>> dict1 = {"key1": "value1", "key2": "value2"} >>...
MadSc13ntist's user avatar
  • 21.7k
538 votes
15 answers
616k views

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]...
user1530318's user avatar
169 votes
20 answers
199k views

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''}...
ensnare's user avatar
  • 42.5k
48 votes
5 answers
118k views

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 ...
elegent's user avatar
  • 4,002
44 votes
2 answers
76k views

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 ...
Acoop's user avatar
  • 2,666
9 votes
5 answers
9k views

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']...
Cora Coleman's user avatar
4 votes
3 answers
9k views

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': ...
imprivate's user avatar
0 votes
6 answers
2k views

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 }, { "...
dclobato's user avatar
1 vote
2 answers
5k views

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", #&...
shekar chandra's user avatar
0 votes
1 answer
8k views

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 ...
Pedro.Alonso's user avatar
  • 1,005

15 30 50 per page