Dictionary in Python

Explain the dictionary in Python.

- Python's built-in data type is dictionary, which defines one-to-one relationships between keys and values.
- Dictionaries consist of pairs of keys and their corresponding values.
- Dictionaries are indexed by keys.
- Dictionary is similar to associative array or hash table of other languages.
- As following example explains further- India, Angel & Cartoon are keys & their corresponding values are Bharat, Mother Teresa & Mickey respectively.
>>> dict = {'India': 'Bharat', 'Angel': ‘Mother Teresa’, 'Cartoon': 'Mickey'}
>>>print dict[India]
Bharat
>>>print dict[Angel]
Mother Teresa
Global variables in Python
Global variables in Python - We can create a config file & store the entire global variable to be shared across modules or script in it.......
Pass optional from one function to another in Python
Pass optional from one function to another - Gather the arguments using the * and ** specifiers in the function's parameter list. This gives us positional arguments as a tuple and the keyword arguments.......
Indexing and slicing operation in sequences
Indexing and slicing operation in sequences - Different types of sequences in python are strings, Unicode strings, lists, tuples, buffers, and xrange objects.......
Post your comment
Discussion Board
update defination
Hello Sir,

I think the following line is not correct:
Dictionaries are indexed by keys

Thanks,
Rajendra
Rajendra 04-20-2015
Dictionary definition is confusing and wrong
Dear Sirs;

You need to update your dictionary definition. Currently it reads:

"Dictionaries consist of pairs of keys and their corresponding values"

It should read-"Dictionaries consist of key, value pairs.

Your definition reads as if there are pairs of keys which is incorrect.
Richard Hess 01-21-2015