Category "dictionary"

How to extract values from key value map?

I have a column of type map, where the key and value changes. I am trying to extract the value and create a new column. Input: ----------------+ |symbols

How to update history dictionary attribute of a class instance and preserve order?

I am new to class programming. I am trying to save initial attributes (which are a dictionary) of my object in its history, and then update history with the cha

Are dictionaries ordered in Python 3.6+?

Dictionaries are insertion ordered as of Python 3.6. It is described as a CPython implementation detail rather than a language feature. The documentation states

Find the sum of values within the values of a nested Dictionary

This is a question based on nested dictionaries. We are given a nested dictionary wherein in the outer dictionary, the name of the match is mentioned and the

Object-like attribute access for nested dictionary

I'm utilising a package which returns a nested dictionary. It feels awkward to access this return object in my class methods with the dictionary syntax, when ev

Does golang have the plan for supporting set datastructure?

This feature can be implemented with 'map'. countrySet := map[string]bool{ "US": true, "JP": true, "KR": true, } But to ease the eyes of readers, 'set'

How do I use the new computeIfAbsent function?

I very much want to use Map.computeIfAbsent but it has been too long since lambdas in undergrad. Almost directly from the docs: it gives an example of the ol

Trouble with output for Fantasy Game Inventory

I'm a beginner working on the Automate the boring stuff with Python book. I'm stuck on this practice problem. The instructions are as follows: List to Dictiona

Create dictionary from an array of objects using property of object as key for the dictionary?

With Swift is it possible to create a dictionary of [String:[Object]] from an array of objects [Object] using a property of those objects as the String key for

Iterator for custom class in Python 3

I'm trying to port a custom class from Python 2 to Python 3. I can't find the right syntax to port the iterator for the class. Here is a MVCE of the real class

How to create a dictionary of two pandas DataFrame columns

What is the most efficient way to organise the following pandas Dataframe: data = Position Letter 1 a 2 b 3 c 4 d 5

Converting cookie string into Python dict

In Fiddler, I captured an HTTPS request with the following cookie string sent from the client (visible in Inspectors > Raw): Cookie: devicePixelRatio=1; ide

Write optimized code which takes following two list of dictionaries as input and gives output as final_result [duplicate]

Inputs: list1 = [{'item_type':1,'value':55, 'title':'abc'},{'item_type':2,'value':43, 'title':'def'},{'item_type':3,'value':35, 'title':'ghi'}

Check if a value is in a list

Does Go have something similar to Python's in keyword? I want to check if a value is in a list. For example in Python: x = 'red' if x in ['red', 'green', 'ye

Overriding dict.update() method in subclass to prevent overwriting dict keys

Earlier today, I read the question "Raise error if python dict comprehension overwrites a key" and decided to try my hand at an answer. The method that natural

Sort dictionary of dictionaries by value

I have this dictionary: statuses = { 'pending' : {'status_for':'all', 'position':1}, 'cancelled' : {'status_for':'all','position':2},

How can I remove a key from a Python dictionary?

Is there a one-line way of deleting a key from a dictionary without raising a KeyError? if 'key' in my_dict: del my_dict['key']

Swift dictionary get key for value

I'm using a swift dictionary of type [UIImage:UIImage], and I'm trying to find a specific key for a given value. In Objective-C I could use allKeysForValue, bu

python check multi-level dict key existence

Many SO posts show you how to efficiently check the existence of a key in a dictionary, e.g., Check if a given key already exists in a dictionary How do I do t

Loop through all nested dictionary values?

for k, v in d.iteritems(): if type(v) is dict: for t, c in v.iteritems(): print "{0} : {1}".format(t, c) I'm trying to loop through a