Wednesday

Chapter – 9: DICTIONARIES || Computer Science || Class 11

 

Chapter – 9: DICTIONARIES

Very Short answer Type Questions Q.1     Why can‟t List can be used as keys?

Ans: List is mutable datatype. And Keys of dictionary must be immutable type. This is the region that

list cannot be used as keys.

Q.2      What type of objects can be used as keys in dictionary? 

Ans: Any immutable objects can be used as keys in dictionary. 

Q.3             Can you change the order of the dictionaries contents?

Ans: Yes, the order of dictionary contents may be changed. Q.4 Can you modify the keys in a dictionary?

Ans: Keys cannot be modified in dictionary while values are mutable in dictionary.   Q.5 Can you modify the value in a dictionary?

Ans: Yes, Values can be modified in dictionaries. Q.6 Is dictionary Mutable? Why?

Ans: Dictionary is mutable type because we can change its values. 

Short Answer Type Questioemns  Q.1 How are dictionaries different from Lists?

Ans: The dictionary is similar to lists in the sense that it is also a collection of data-items but it is

different from lists in the sense that lists are sequential collections(ordered) and dictionaries are non-sequential collections(unordered).

 Elements in lists or tuples can be accessed by using indexes. But in dictionaries the values can be obtained using keys. By changing the sequence of key we can shuffle the order of elements of dictionary while this thing is not possible in list.

Q.2         When are dictionaries more useful than lists?

Ans: Dictionaries can be much more useful than lists when we wanted to store all our friends cellphone numbers. We could create a list of pairs,(name of friend, phone number), but once this list becomes long enough searching this list for a specific phone number will get-time consuming. Better would be if we could index the list by our friend‘s name. This is precisely what a dictionary does.

Q.3    Discuss the utility and significance of Dictionaries.

Ans: Dictionaries can be much more useful than lists when we wanted to store all our friends cellphone numbers. We could create a list of pairs,(name of friend, phone number), but once this list becomes long enough searching this list for a specific phone number will get-time consuming. Better would be if we could index the list by our friend‘s name. This is precisely what a dictionary does.

Q.4            Why is a dictionary termed as an unordered collection of objects?

Ans: But in dictionaries the values can be obtained using keys. By changing the sequence of key we can shuffle the order of elements of dictionary while this thing is not possible in list. In dictionaries there is no index. It uses its keys as index which can be rearranged. That‘s why a dictionary termed as an unordered collection of objects

Q.5    How is clear() function different from del <dict> Statement?

Ans: clear() removes all the elements of a dictionary and makes it empty dictionary while del statement removes the complete dictionary as an object. After del statement with a dictionary name, that dictionary object no longer exists, not even empty dictionary. Q.6     What is the output produced by the following code - 

                                                                 Ans:

 

Skill Based Questions

Q.1     WAP that repeatedly asks the user to enter product names and prices. Store all of them in a dictionary whose keys are product names and values are prices. And also

Q.2     WAP to create a dictionary named year whose keys are month names and values are their corresponding number of days.

Ans:

 

 

 

 

 

0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.