24 solutions available
Question 1Why are dictionaries called mutable types?
Question 2What are different ways of creating dictionaries?
Question 3What values can we have in a dictionary?
Question 9How do you add key:value pairs to an existing dictionary?
Question 10Can you remove key:value pairs from a dictionary and if so, how?
Question 8Which of the following can be used to delete item(s) from a dictionary?del statementpop( )popitem( )all of these
Question 23What will be the output of following Python code?d1 = {"a":10,"b":2,"c":3} str1="" for i in d1: str1 = str1 + str(d1[i]) + " "...
Question 24Running the code sorted(my_dictionary, reverse = True) on a dictionary named my_dictionary will return results sorted in what...
Question 5Can you change the order of dictionary's contents, i.e., can you sort the contents of a dictionary ?
Question 15Can you use sum( ) for calculating the sum of the values of a dictionary ?
Question 17What is the use of copy( ) function ?
Question 18Discuss the working of copy( ) if(i) the values are of immutable types,(ii) the values are of mutable types.
Question 9(c)Predict the output:text = "abracadabraaabbccrr" counts = {} ct = 0 lst = [] for word in text: if word not in lst:...
Question 9(d)Predict the output:list1 = [2, 3, 3, 2, 5,3, 2, 5, 1,1] counts = {} ct = 0 lst = [] for num in list1: if num not in lst:...
Question 10Create a dictionary 'ODD' of odd numbers between 1 and 10, where the key is the decimal number and the value is the corresponding number...
Question 11(a)Find the errors:text = "abracadbra" counts = {} for word in text : counts[word] = counts[word] + 1
Question 12(a)Predict the output:fruit = {} L1 = ['Apple', 'banana', 'apple'] for index in L1 : if index in fruit: fruit[index] += 1 else :...
Question 13(b)Predict the outputa = {'a':1, 'b':2, 'c':3} print(a['a','b'])
Question 14Find the error/output. Consider below given two sets of codes. Which one will produce an error? Also, predict the output produced by the...
Question 15Predict the output :dct = {} dct[1] = 1 dct ['1'] = 2 dct[1.0] = 4 sum = 0 for k in dct: print(k, sum) sum += dct[k] print(sum)
Question 16Fill in the blanks of the following code so that the values and keys of dictionary d are inverted to create dictionary fd.d = {'a':1,...
Question 4Repeatedly 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...
Question 6Create a dictionary whose keys are month names and whose values are the number of days in the corresponding months.(a) Ask the user to...
Question 7Can you store the details of 10 students in a dictionary at the same time ? Details include - rollno, name, marks, grade etc. Give example...