# HG changeset patch # User Nishanth # Date 1285173941 -19800 # Node ID 35a3811ca91e28d19e10b76f45f76e28480d3d0a # Parent a005328abdf02851d28a44490fd64dd1c8394491 reviewed getting_started_with_lists a.k.a liststart diff -r a005328abdf0 -r 35a3811ca91e liststart.rst --- a/liststart.rst Wed Sep 22 21:49:08 2010 +0530 +++ b/liststart.rst Wed Sep 22 22:15:41 2010 +0530 @@ -1,3 +1,9 @@ +.. #[Nishanth]: liststart is not a good name. there is no consistency. + Use underscores or hyphens instead of spaces and + make the filename from LO name + Ex: getting_started_with_lists (or) + getting_started_lists + Hello friends and welcome to the tutorial on getting started with lists. @@ -7,26 +13,31 @@ In this tutorial we will be getting acquainted with a python data structure called lists. We will learn : - * How to create lists. - * Structure of lists. - * Access list elements. - * Append elements to lists. - * Deleting elements from lists. + * How to create lists + * Structure of lists + * Access list elements + * Append elements to lists + * Deleting elements from lists -I hope you have ipython running on your system . +.. #[Nishanth]: Did you compile this?? + There must an empty before the bulleted list + +I hope you have ipython running on your system. + +.. #[Nishanth]: need not specify. Implicit that IPython is running List is a compound data type, it can contain data of other data -types.List is also a sequence data type, all the elements are in +types. List is also a sequence data type, all the elements are in order and there order has a meaning. -We will first create an empty list with no elements. On your ipython +We will first create an empty list with no elements. On your IPython shell type :: empty = [] type(empty) -This is an empty list without any elements . +This is an empty list without any elements. * Filled lists @@ -36,24 +47,23 @@ Thus the simplest way of creating a list is typing out a sequence of comma-separated values (items) between square brackets. -List items need not all have the same data type. +All the list items need not have the same data type. +.. #[Nishanth]: do not use "You" or anything else. Stick to "We" -As you can see lists can contain different kinds of data. In the +As we can see lists can contain different kinds of data. In the previous example 'spam' and 'eggs' are strings and 100 and 1.234 -integer and float . Thus you can put elements of heterogenous types in -lists. Thus list themselves can be one of the element types possible -in lists. Thus lists can also contain other lists in it . Example :: +integer and float. Thus we can put elements of heterogenous types in +lists. Thus list themselves can be one of the element types possible +in lists. Thus lists can also contain other lists. Example :: list_in_list=[[4,2,3,4],'and', 1, 2, 3, 4] - We access list elements using the number of index. The -index begins from 0. So for list, nonempty , nonempty[0] gives the -first element , nonempty[1] the second element and so on and +index begins from 0. So for list nonempty, nonempty[0] gives the +first element, nonempty[1] the second element and so on and nonempty[3] the last element.:: - nonempty[0] nonempty[1] nonempty[3] @@ -65,16 +75,26 @@ nonempty[-4] -1 being the last element , -2 second to last and -4 being the first - element. +element. + +.. #[Nishanth]: -1 being last element sounds like -1 is the last element + Instead say -1 gives the last element which is 4 -* =append= elements We can append elements to the end of a list using -append command. :: +.. #[Nishanth]: Instead of saying -4 being the first, say -4 gives 4th + from the last which is the first element. + +* =append= elements +We can append elements to the end of a list using append command. :: nonempty.append('onemore') nonempty.append(6) nonempty -As you can see non empty appends 'onemore' and 6 at the end. +As we can see non empty appends 'onemore' and 6 at the end. + +.. #[Nishanth]: First show an example with only one append. + may be show the value of a after first append + then show what happens after second append Using len function we can check the number of elements in the list nonempty. Because we just appended two elements at the end this @@ -82,12 +102,17 @@ len(nonempty) -Just like you can append elements to a list you can also remove them . -Their are two ways of doing one is by index no. :: +.. #[Nishanth]: the "because ..." can be removed. You can simply + say len gives the no.of elements which is 6 here + +Just like we can append elements to a list we can also remove them. +There are two ways of doing. One is by using index. :: del(nonempty[1]) -deletes the element at index no.1, i.e the second element of the +.. #[Nishanth]: do not use "You" or anything else. Stick to We + +deletes the element at index 1, i.e the second element of the list, 'eggs'. The other way is removing element by content. Lets say one wishes to delete 100 from nonempty list the syntax of the command should be :: @@ -102,20 +127,24 @@ a.remove('spam') a -If we check a now we will see that the first element 'spam' is removed -thus remove removes only the first instance of the element by sequence +If we check a now we will see that the first occurence 'spam' is removed +thus remove removes the first occurence of the element in the sequence and leaves others untouched. {{{Slide for Summary }}} -In this tutorial we came across a sequence data type called lists. +In this tutorial we came across a sequence data type called lists. :: + * We learned how to create lists. * Append elements to list. * Delete Element from list. * And Checking list length. +.. #[Nishanth]: See the diff. I have corrected punctuation in many places. + The first thing you do before committing is compile the script. + I have corrected syntax errors also in many places. {{{ Sponsored by Fossee Slide }}} @@ -127,4 +156,5 @@ Author : Amit Sethi -First Reviewer : +First Reviewer : +Second Reviewer : Nishanth diff -r a005328abdf0 -r 35a3811ca91e progress.org --- a/progress.org Wed Sep 22 21:49:08 2010 +0530 +++ b/progress.org Wed Sep 22 22:15:41 2010 +0530 @@ -13,7 +13,7 @@ | 2.4 LO: | other types of plots | 3 | Anoop | | | | 2.5 LO: | module level assessment | 3 | Nishanth | | | |---------+----------------------------------------+-------+----------+---------------------+---------------------| -| 3.1 LO: | getting started with lists | 2 | Amit | Madhu (Pending) | Nishanth (Pending) | +| 3.1 LO: | getting started with lists | 2 | Amit | Madhu (Pending) | Nishanth (Done) | | 3.2 LO: | getting started with =for= | 2 | Anoop | | | | 3.3 LO: | getting started with strings | 2 | Madhu | | | | 3.4 LO: | getting started with files | 3 | Punch | | |