dictionaries/questions.rst
changeset 261 c7f0069d698a
equal deleted inserted replaced
260:25b4e962b55e 261:c7f0069d698a
       
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4 .. A mininum of 8 questions here (along with answers)
       
     5 
       
     6 1. Container-ship of values can be checked in a python dictionary
       
     7 
       
     8    a. True
       
     9    #. False
       
    10 
       
    11 Answer: False
       
    12 
       
    13 2. Container-ship of only keys can be checked in a python dictionary
       
    14 
       
    15    a. True
       
    16    #. False
       
    17 
       
    18 Answer: True
       
    19 
       
    20 3. The value in a dictionary can be
       
    21 
       
    22    a. String
       
    23    #. Integer
       
    24    #. Any data type
       
    25    #. None
       
    26 
       
    27 Answer: Any data type
       
    28 
       
    29 4. Python lists can be made as a key in dictionaries.
       
    30 
       
    31    a. True
       
    32    #. False
       
    33 
       
    34 Answer: False
       
    35 
       
    36 5. Given a python dictionary ``x = {'a' : 1, 'b' : 2, 'c' : 3, 'd' :
       
    37    4}``. When printed using ``print x`` will generate the output in
       
    38    the order.  {key-value pair ``'a':1`` identified as a, ``'b':2``
       
    39    identified as b and so on}
       
    40 
       
    41    a. a, b, c, d
       
    42    #. d, c, b, a
       
    43    #. a, c, b, d
       
    44    #. b, d, a, c
       
    45    #. Cannot predict
       
    46 
       
    47 Answer: Cannot predict
       
    48 
       
    49 6. The python dictionary ``x = {'a' : ['a', 'b', 'c'], 'b' : (1, 2, 3),
       
    50    1 : {1 : 'one', 2 : 'two'}, 10 : {10 : 'ten', 11 : 'eleven'}}`` is
       
    51    invalid.
       
    52 
       
    53    a. True
       
    54    #. False
       
    55 
       
    56 Answer: False
       
    57 
       
    58 7. Consider the python dictionary ``x = {'a' : ['a','b','c'], 'b' :
       
    59    (1, 2, 3), 1 : {1 : 'one', 2 : 'two'}, 10 : {10 : 'ten', 11 :
       
    60    'eleven'}}``. And after applying the code below, what will be the
       
    61    output of ``print x['a']``
       
    62    ::
       
    63 
       
    64       x['a'].extend(['d', 'e'])
       
    65       x['a'][3] = x[10]
       
    66 
       
    67    a. Code will result in error
       
    68    #. ['a', 'b', 'c', {11: 'eleven', 10: 'ten'}, 'e']
       
    69    #. {10 : 'ten', 11 : 'eleven'}
       
    70    #. {10 : 'ten', 11 : 'eleven', 'a' : ['a', 'b', 'c']}
       
    71    #. (1, 2, 3, ['a', 'b', 'c'])
       
    72 
       
    73 Answer: ['a', 'b', 'c', {11: 'eleven', 10: 'ten'}, 'e']
       
    74 
       
    75 8. Consider the python dictionary ``x = {'a' : ['a','b','c'], 'b' :
       
    76    (1, 2, 3), 1 : {1 : 'one', 2 : 'two'}, 10 : {10 : 'ten', 11 :
       
    77    'eleven'}}``. The code ``(1, 2, 3) in x.values()`` will return
       
    78 
       
    79    a. True
       
    80    #. False
       
    81    #. Container-ship of values cannot be checked in dictionaries
       
    82    #. The dictionary is invalid
       
    83 
       
    84 Answer: True
       
    85 
       
    86 Larger Questions
       
    87 ----------------
       
    88 
       
    89 .. A minimum of 2 questions here (along with answers)
       
    90 
       
    91 1. Write a python script which can print the numbers from 1 to
       
    92    999(both included) in words.
       
    93 
       
    94 2. Given the list of marks of students in a class, write a program to
       
    95     find the duplicate marks. List the duplicate marks and also print
       
    96     the number of duplicates for each.
       
    97 
       
    98 3. Given a list of words, find the anagrams in it and list them.
       
    99     [meats, tap, steep, tames, hare, pets, had, apt, teams, dark,
       
   100     dealer, once, rhea, cloud, step, steam, have, could, ounce, pest,
       
   101     head, leader, cone, rare, rear, hear, pat, mates]
       
   102