Page 1 - Home Assignment - DICTIONARY
P. 1

Home Assignment


                                          Computer Science

                                                     Class – XI


                                              Topic: DICTIONARY






               1.  Dictionary is an unordered set of elements. Explain.

               2.  _____________ must be unique and immutable within a dictionary.
               3.  Internally dictionaries are stored as ______________.

               4.  Based on the definition of following two dictionaries answer the following questions:


                   D1 = {1: 'SUN', 2: 'MON', 3: 'TUE', 4: 'WED', 5: 'THU', 6: 'FRI', 7: 'SAT'}
                   D2 = {'V': 'VIOLET', 'I': 'INDIGO', 'B': 'BLUE', 'G': 'GREEN', 'Y': 'YELLOW', 'O': ORANGE', 'R': 'RED'}


                   a)  print(D1[3])
                   b)  print(D1[-3])
                   c)  print(D2['Y'])
                   d)  print(dict())
                   e)  print('B' in D2)
                   f)  print(5 not in D1)
                   g)  D1.get(8)
                   h)  D2.get('O')

                   i)  D1.items()
                   j)  D1.keys()
                   k)  D2.values()
                   l)  print(dict.fromkeys([2,4,6], 'EVEN'))
                   m) X={1:10,2:20,3:30}
                       Y={2:200,4:400}
                       X.update(Y)
                       print(X)
                       print(Y)
                   n)  D1['W']='WEEKDAYS'
                       print(len(D1))


               5.  Differentiate creating a copy of dictionary through = operator to a copy of the same with
                   copy() function.

               6.  Differentiate pop() and popitem(). Explain through an example.
   1   2