--- a/basic_python/list_tuples.rst Fri Aug 21 16:22:56 2009 +0530
+++ b/basic_python/list_tuples.rst Sat Aug 22 19:30:14 2009 +0530
@@ -1,6 +1,9 @@
Lists and Tuples
================
+Lists
+-----
+
Python provides an intuitive way to represent a group items, called *Lists*. The
items of a *List* are called its elements. Unlike C/C++, elements can be of any
type. A *List* is represented as a list of comma-sepated elements with square
@@ -12,9 +15,12 @@
Common List Operations
-----------------------
+~~~~~~~~~~~~~~~~~~~~~~
+
+The following are some of the most commonly used operations on *Lists*.
+~~~~~~~~
Indexing
~~~~~~~~
@@ -31,6 +37,7 @@
-1.
+~~~~~~~~~~~~~
Concatenating
~~~~~~~~~~~~~
@@ -42,6 +49,7 @@
[54, 75, 23, 'write', 67, 'read']
+~~~~~~~
Slicing
~~~~~~~
@@ -88,9 +96,11 @@
[1, 5, 9]
+~~~~~~~~~~~~~~
Multiplication
~~~~~~~~~~~~~~
+
A *List* can be multiplied with an integer to repeat itself::
>>> [20] * 5
@@ -99,6 +109,7 @@
[42, 'Python', 54, 42, 'Python', 54, 42, 'Python', 54]
+~~~~~~~~~~
Membership
~~~~~~~~~~
@@ -114,6 +125,7 @@
False
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
Length, Maximum and Minimum
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -130,6 +142,7 @@
1
+~~~~~~~~~~~~~~~~~
Changing Elements
~~~~~~~~~~~~~~~~~
@@ -141,6 +154,7 @@
[1, 3, 9, 7]
+~~~~~~~~~~~~~~~~~
Deleting Elements
~~~~~~~~~~~~~~~~~
@@ -155,6 +169,7 @@
[1, 5, 7]
+~~~~~~~~~~~~~~~~
Assign to Slices
~~~~~~~~~~~~~~~~
@@ -177,7 +192,7 @@
None, Empty Lists, and Initialization
--------------------------------------
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An *Empty List* is a *List* with no elements and is simply represented as
[]. A *None List* is one with all elements in it being **None**. It serves
@@ -193,7 +208,7 @@
Nested Lists
-------------
+~~~~~~~~~~~~
As mentioned earlier, a List can contain elements of any data type. This also
implies a *List* can have a *Lists* themselves as its elements. These are
@@ -203,7 +218,7 @@
List Methods
-------------
+~~~~~~~~~~~~
A method is a function that is coupled to an object. More about objects
and its methods are discussed in Advanced Python module. In general, a
@@ -220,6 +235,7 @@
Some of the most commonly used *List* methods are as follows:
+~~~~~~
append
~~~~~~
@@ -233,6 +249,7 @@
It is important to note that append changes the *List* in-place.
+~~~~~
count
~~~~~
@@ -246,6 +263,7 @@
1
+~~~~~~
extend
~~~~~~
@@ -261,6 +279,7 @@
using the + operator returns a new list.
+~~~~~
index
~~~~~
@@ -272,6 +291,7 @@
3
+~~~~~~
insert
~~~~~~
@@ -286,6 +306,7 @@
The *insert* method changes the *List* in-place.
+~~~
pop
~~~
@@ -304,6 +325,7 @@
The *pop* method changes the *List* in-place.
+~~~~~~
remove
~~~~~~
@@ -316,6 +338,7 @@
[1, 3, 4, 2, 5, 2]
+~~~~~~~
reverse
~~~~~~~
@@ -329,6 +352,7 @@
['tim', 'alex', 'guido']
+~~~~
sort
~~~~
@@ -353,7 +377,7 @@
List Comprehensions
--------------------
+~~~~~~~~~~~~~~~~~~~
List Comprehension is a convenvience utility provided by Python. It is a
syntatic sugar to create *Lists*. Using *List Comprehensions* one can create