Class 11 IP Chapter 8 Dictionaries Solutions Sumita Arora New Syllabus / Uncategorized / By Neha Exercise 8.1 9. How do you add key : value pairs to an existing dictionary ? ...click here for answer 10. Can you remove key:value pairs from a dictionary and if so, how ? ...click here for answer 7. Can you change an element of a sequence or collection ? What if the collection is a dictionary ? What if the sequence is a string ? ...click here for answer 8. What do you understand by ordered collection and unordered collection ? Give examples. ...click here for answer 6. Which of the following types qualify to be the keys of a dictionary ? ...click here for answer 4. How are individual elements of dictionaries accessed ? ...click here for answer 5. How is indexing of a dictionary different from that of a list or a string ? ...click here for answer 2. What are different ways of creating dictionaries ? ...click here for answer 1. Why are dictionaries called mutable types ? ...click here for answer 3. What values can we have in a dictionary? ...click here for answer Back Exercise Part A 7. Can you check for a value inside a dictionary using in operator? How will you check for a value inside a dictionary using in operator ? ...click here for answer 10. How is clear() function different from del statement ? ...click here for answer 8. Dictionary is a mutable type, which means you can modify its contents ? What all modifiable in a dictionary ? Can you modify the keys of a dictionary ? ...click here for answer 5. Can you change the order of dictionary’s contents, i.e., can you sort the contents of a dictionary ? ...click here for answer 6. In no more than one sentence, explain the following Python error and how it would arise: TypeError: unhashable type: ’list’ ...click here for answer 4. What all types of values can you store in : (a) dictionary-values ? (b) dictionary-keys ? ...click here for answer 2. What type of objects can be used as keys in dictionaries ? ...click here for answer 3. Though tuples are immutable type, yet they cannot always be used as keys in a .dictionary. What is the condition to use tuples as a key in a dictionary ? ...click here for answer 1. Why is a dictionary termed as an unordered collection of objects ? ...click here for answer 9. How is del D and del D[] different from one another if D is a dictionary ? ...click here for answer Back Exercise Part B 10. Find the errors ...click here for answer 12 . Predict the output ...click here for answer 13. Find the error/output. Consider below given two sets of codes. Which one will produce an error? Also predict the output produced by the correct code. ...click here for answer 11. Predict the output ...click here for answer 9. Predict the output ...click here for answer 7. Consider the following code and then answer the questions that follow : ...click here for answer 8. What will be the output produced by following code ? ...click here for answer 6. What is the output produced by above code : ...click here for answer 3. The following code has two dictionaries with tuples as keys. While one of these dictionaries being successfully created, the other is giving some error. Find out which dictionary will be created successfully and which one will give error and correct it : dict1 = ...click here for answer 4. Nesting of dictionary allows you to store a dictionary inside another dictionary. Then why is following code raising error ? What can you do to correct it? ...click here for answer 1. Which of the following will result in an error for a given valid dictionary D ? ...click here for answer 2. The following code is giving some error. Find out the error and correct it. d1 = ...click here for answer 5. Why is following code not giving correct output even when 25 is a member of the dictionary? ...click here for answer Back Exercise Part C 7. Write a program that checks if two same values in a dictionary have different keys. That is, for dictionary D1 = { ‘a’ : 10, ‘b 20, ‘c’ : 10], the program should print “2 keys have same values” and for dictionary D2 = { ‘a’ : 10, ‘b’ : 20, ‘c’ : 30) , the program should print “No keys have same values”. # Code ...click here for answer 6. Given two dictionaries say D1 and D2. Write a program that lists the overlapping keys of the two dictionaries, i.e., if a key of D1 is also a key of D2, the list it. ...click here for answer 5. Given the dictionary x = {‘k1’: ‘v1’, ‘k2’: ‘v2’, ‘k3’: ‘v3’}, create a dictionary with the opposite mapping i.e., write a program to create the dictionary as : inverted_x = { ‘ v1’ : ‘ k1’ , ‘ v2 ‘ : ‘ k2 ‘ , ‘ v3 ‘ : ‘ k3 ‘ } ...click here for answer 4. Can you store the details of 10 students in a dictionary at the same time ? Details include – rollno, name marks, grade etc. Give example to support your answer. ...click here for answer 2. Write a program that repeatedly asks the user to enter product names and prices. Store all of these in a dictionary whose keys are the product names and whose values are the prices. When the user is done entering products and prices, allow them to repeatedly enter a product name and print the corresponding price or a message if the product is not in the dictionary. # Code ...click here for answer 3. Create a dictionary whose keys are month names and whose values are the number o f days in the corresponding months. ...click here for answer 1. Repeatedly ask the user to enter a team name and how many games the team has won and how many they lost. Store this information in a dictionary where the keys are the team names and the values are lists of the form [wins, losses]. (a) Using ...click here for answer