Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1. What is mapping?

2. Is dictionary a mapping?
3. What is the meaning of traversing a dictionary?
4. What are the characteristics of a dictionary. Define any two with
examples.
5. Use of get() and item() method.
6. Use of update() command.
7. How are objects stored in a list and a dictionary?
8. When a dictionary is more useful than a list?

Answers:
1. Mapping is the relation of a value with a key value.

2. Yes, dictionary is a mapping because it helps to map a value


with a particular key value.

3. Meaning of traversing a dictionary is to traverse through the


elements i.e. the key value pairs.

4. Characteristics of a dictionary are:


i) Elements are stored as a key value pair in a dictionary.
Example: {“hello”:21, “days”:33}
ii) Dictionary is a mutable datatype
iii) Dictionary can consist of multiple datatypes under a single
unit.
iv) Dictionary have unique keys for all values.

Example: {“hello”:21, “world”:22}


v) Dictionary doesn’t contain elements in an ordered or
particular sequence.

5. get() method is used to access a particular value in a dictionary.

items() method returns all the key:value pairs as a tuple .

6. update() method updates the dictionary with a key:value pair.

7. Objects are stored in a list in terms of its index position whereas


in dictionary, the objects are stored in terms of key:value pairs.

8. Accessing the elements in a dictionary is pretty easy as it can be


accessed by directly mentioning the key or the value whereas in
the list, the elements can be accessed by only knowing the
index position of the element.

You might also like