dictionaries/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Thu, 11 Nov 2010 10:37:26 +0530
changeset 465 78d20cd87c7e
parent 261 c7f0069d698a
permissions -rw-r--r--
Added questions to writing python scripts.

Objective Questions
-------------------

.. A mininum of 8 questions here (along with answers)

1. Container-ship of values can be checked in a python dictionary

   a. True
   #. False

Answer: False

2. Container-ship of only keys can be checked in a python dictionary

   a. True
   #. False

Answer: True

3. The value in a dictionary can be

   a. String
   #. Integer
   #. Any data type
   #. None

Answer: Any data type

4. Python lists can be made as a key in dictionaries.

   a. True
   #. False

Answer: False

5. Given a python dictionary ``x = {'a' : 1, 'b' : 2, 'c' : 3, 'd' :
   4}``. When printed using ``print x`` will generate the output in
   the order.  {key-value pair ``'a':1`` identified as a, ``'b':2``
   identified as b and so on}

   a. a, b, c, d
   #. d, c, b, a
   #. a, c, b, d
   #. b, d, a, c
   #. Cannot predict

Answer: Cannot predict

6. The python dictionary ``x = {'a' : ['a', 'b', 'c'], 'b' : (1, 2, 3),
   1 : {1 : 'one', 2 : 'two'}, 10 : {10 : 'ten', 11 : 'eleven'}}`` is
   invalid.

   a. True
   #. False

Answer: False

7. Consider the python dictionary ``x = {'a' : ['a','b','c'], 'b' :
   (1, 2, 3), 1 : {1 : 'one', 2 : 'two'}, 10 : {10 : 'ten', 11 :
   'eleven'}}``. And after applying the code below, what will be the
   output of ``print x['a']``
   ::

      x['a'].extend(['d', 'e'])
      x['a'][3] = x[10]

   a. Code will result in error
   #. ['a', 'b', 'c', {11: 'eleven', 10: 'ten'}, 'e']
   #. {10 : 'ten', 11 : 'eleven'}
   #. {10 : 'ten', 11 : 'eleven', 'a' : ['a', 'b', 'c']}
   #. (1, 2, 3, ['a', 'b', 'c'])

Answer: ['a', 'b', 'c', {11: 'eleven', 10: 'ten'}, 'e']

8. Consider the python dictionary ``x = {'a' : ['a','b','c'], 'b' :
   (1, 2, 3), 1 : {1 : 'one', 2 : 'two'}, 10 : {10 : 'ten', 11 :
   'eleven'}}``. The code ``(1, 2, 3) in x.values()`` will return

   a. True
   #. False
   #. Container-ship of values cannot be checked in dictionaries
   #. The dictionary is invalid

Answer: True

Larger Questions
----------------

.. A minimum of 2 questions here (along with answers)

1. Write a python script which can print the numbers from 1 to
   999(both included) in words.

2. Given the list of marks of students in a class, write a program to
    find the duplicate marks. List the duplicate marks and also print
    the number of duplicates for each.

3. Given a list of words, find the anagrams in it and list them.
    [meats, tap, steep, tames, hare, pets, had, apt, teams, dark,
    dealer, once, rhea, cloud, step, steam, have, could, ounce, pest,
    head, leader, cone, rare, rear, hear, pat, mates]