getting-started-with-lists/questions.rst
author Amit Sethi
Fri, 12 Nov 2010 15:23:54 +0530
changeset 489 bc8d01c3c9b3
parent 374 57d145c18ccd
permissions -rw-r--r--
Added quickref for testing-debugging
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
225
94bcf44b05ad Minor changes to questions.rst template.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
     1
Objective Questions
94bcf44b05ad Minor changes to questions.rst template.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
     2
-------------------
213
6b10318465d4 Added Templates.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
223
ce0e8c99eaee Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents: 216
diff changeset
     4
.. A mininum of 8 questions here (along with answers)
213
6b10318465d4 Added Templates.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
     6
1. How do you create an empty list? ::
223
ce0e8c99eaee Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents: 216
diff changeset
     7
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
     8
   empty=[]
223
ce0e8c99eaee Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents: 216
diff changeset
     9
   
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    10
2. What is the most important property of sequence data types like lists?
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    11
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    12
   The elements are in order and can be accessed by index numbers.
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    13
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    14
3. Can you have a list inside a list ? 
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    15
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    16
   Yes,List can contain all the other data types, including list. 
223
ce0e8c99eaee Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents: 216
diff changeset
    17
   
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    18
   Example:
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    19
   list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']
223
ce0e8c99eaee Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents: 216
diff changeset
    20
   
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    21
4. What is the index number of the first element in a list?
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    22
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    23
   0
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    24
   nonempty = ['spam', 'eggs', 100, 1.234]
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    25
   nonempty[0]
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    26
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    27
5. How would you access the end of a list without finding its length?
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    28
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    29
   Using negative indices. We can the list from the end using negative indices.
223
ce0e8c99eaee Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents: 216
diff changeset
    30
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    31
   ::
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    32
   nonempty = ['spam', 'eggs', 100, 1.234]
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    33
   nonempty[-1]
213
6b10318465d4 Added Templates.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    34
320
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    35
6. What is the function to find the length of a list?
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    36
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    37
   len
223044cf254f Adding new format st-scripts with questions etc for basic-data-type and
amit
parents: 225
diff changeset
    38
374
57d145c18ccd Adding metadata to getting started with lists.
amit
parents: 342
diff changeset
    39
7. Delete the last element from list sq=[5,4,3,2,1,0]
57d145c18ccd Adding metadata to getting started with lists.
amit
parents: 342
diff changeset
    40
57d145c18ccd Adding metadata to getting started with lists.
amit
parents: 342
diff changeset
    41
   del(sq[-1])
57d145c18ccd Adding metadata to getting started with lists.
amit
parents: 342
diff changeset
    42
   
57d145c18ccd Adding metadata to getting started with lists.
amit
parents: 342
diff changeset
    43
8. How many will you have to use remove function to remove all 6's from the given list sq=[2,5,6,7,6,4,6]?
57d145c18ccd Adding metadata to getting started with lists.
amit
parents: 342
diff changeset
    44
57d145c18ccd Adding metadata to getting started with lists.
amit
parents: 342
diff changeset
    45
   3
213
6b10318465d4 Added Templates.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    46
225
94bcf44b05ad Minor changes to questions.rst template.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
    47
Larger Questions
94bcf44b05ad Minor changes to questions.rst template.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
    48
----------------
213
6b10318465d4 Added Templates.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    49
223
ce0e8c99eaee Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents: 216
diff changeset
    50
.. A minimum of 2 questions here (along with answers)
213
6b10318465d4 Added Templates.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    51
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 320
diff changeset
    52
1. Add all elemets of seq1=['e','f','g','h']
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 320
diff changeset
    53
to the sequence seq=['a','b','c','d']
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 320
diff changeset
    54
   
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 320
diff changeset
    55
2. Delete all elements of seq1=[3,5,6] from sequence
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 320
diff changeset
    56
   seq=[1,2,3,4,5,6,7,8,9]