getting-started-with-lists/questions.rst.orig
author bhanu
Mon, 15 Nov 2010 15:20:54 +0530
changeset 509 0775f177947a
parent 418 8a42b4203f6d
permissions -rw-r--r--
Language check done for `writing python scripts`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
418
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     1
Objective Questions
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     2
-------------------
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     3
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     4
.. A mininum of 8 questions here (along with answers)
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     5
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     6
1. How do you create an empty list? ::
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     7
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     8
       empty=[]
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
     9
   
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    10
2. What is the most important property of sequence data types like lists?
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    11
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    12
   The elements are in order and can be accessed by index numbers.
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    13
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    14
3. Can you have a list inside a list ? 
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    15
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    16
   Yes,List can contain all the other data types, including list. 
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    17
   
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    18
   Example:
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    19
   list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    20
   
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    21
4. What is the index number of the first element in a list?
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    22
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    23
   0
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    24
   nonempty = ['spam', 'eggs', 100, 1.234]
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    25
   nonempty[0]
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    26
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    27
5. How would you access the end of a list without finding its length?
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    28
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    29
   Using negative indices. We can the list from the end using negative indices.
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    30
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    31
   ::
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    32
   nonempty = ['spam', 'eggs', 100, 1.234]
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    33
   nonempty[-1]
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    34
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    35
6. What is the function to find the length of a list?
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    36
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    37
   len
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    38
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    39
7. Delete the last element from list sq=[5,4,3,2,1,0]
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    40
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    41
   del(sq[-1])
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    42
   
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
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]?
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    44
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    45
   3
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    46
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    47
Larger Questions
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    48
----------------
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    49
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    50
.. A minimum of 2 questions here (along with answers)
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    51
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    52
1. Add all elemets of seq1=['e','f','g','h']
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    53
to the sequence seq=['a','b','c','d']
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    54
   
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    55
2. Delete all elements of seq1=[3,5,6] from sequence
8a42b4203f6d "Merging heads"
Amit Sethi
parents:
diff changeset
    56
   seq=[1,2,3,4,5,6,7,8,9]