Top "Dictionary" questions

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

Iterating over dictionaries using 'for' loops

I am a bit puzzled by the following code: d = {'x': 1, 'y': 2, 'z': 3} for key in d: print key, 'corresponds …

python python-2.7 dictionary
Check if a given key already exists in a dictionary

I wanted to test if a key exists in a dictionary before updating the value for the key. I wrote …

python dictionary
How can I add new keys to a dictionary?

Is it possible to add a key to a Python dictionary after it has been created? It doesn't seem to …

python dictionary lookup
How do I sort a dictionary by value?

I have a dictionary of values read from two fields in a database: a string field and a numeric field. …

python sorting dictionary
How do I efficiently iterate over each entry in a Java Map?

If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained …

java dictionary collections iteration
How do I merge two dictionaries in a single expression in Python (taking union of dictionaries)?

I have two Python dictionaries, and I want to write a single expression that returns these two dictionaries, merged (i.…

python dictionary merge
Determine the type of an object?

Is there a simple way to determine if a variable is a list, dictionary, or something else? I am getting …

python dictionary types typeof
Delete an element from a dictionary

Is there a way to delete an item from a dictionary in Python? Additionally, how can I delete an item …

python dictionary del
What is the best way to iterate over a dictionary?

I've seen a few different ways to iterate over a dictionary in C#. Is there a standard way?

c# dictionary loops
How to remove a key from a Python dictionary?

When deleting a key from a dictionary, I use: if 'key' in my_dict: del my_dict['key'] Is there …

python dictionary data-structures unset