Top "Dictionary" questions

A dictionary maps keys to values allowing efficient retrieval of values by keys.

Get key by value in dictionary

I made a function which will look up ages in a Dictionary and show the matching name: dictionary = {'george' : 16, 'amber' : 19} …

python dictionary
Add a new item to a dictionary in Python

I want to add an item to an existing dictionary in Python. For example, this is my dictionary: default_data = { …

python dictionary items
Sort a Map<Key, Value> by values

I am relatively new to Java, and often find that I need to sort a Map<Key, Value> …

java sorting dictionary collections
How can I sort a dictionary by key?

What would be a nice way to go from {2:3, 1:89, 4:5, 3:0} to {1:89, 2:3, 3:0, 4:5}? I checked some posts but they all use the "sorted" …

python sorting dictionary
How to directly initialize a HashMap (in a literal way)?

Is there some way of initializing a Java HashMap like this?: Map<String,String> test = new HashMap<…

java dictionary collections initialization
How to return dictionary keys as a list in Python?

In Python 2.7, I could get dictionary keys, values, or items as a list: >>> newdict = {1:0, 2:0, 3:0} >>> …

python python-3.x list dictionary python-2.x
Getting key with maximum value in dictionary?

I have a dictionary: keys are strings, values are integers. Example: stats = {'a':1000, 'b':3000, 'c': 100} I'd like to get 'b' …

python dictionary max
How can I get list of values from dict?

How can I get a list of the values in a dict in Python? In Java, getting the values of …

python list dictionary
Convert two lists into a dictionary

Imagine that you have: keys = ['name', 'age', 'food'] values = ['Monty', 42, 'spam'] What is the simplest way to produce the following …

python list dictionary
Convert a String representation of a Dictionary to a dictionary?

How can I convert the str representation of a dict, such as the following string, into a dict? s = "{'muffin' : …

python string dictionary