getting-started-with-lists/script.rst
changeset 466 00c1ba1cb9ef
parent 441 430035b678f7
child 490 2280bbdce638
equal deleted inserted replaced
451:c61ed190af5e 466:00c1ba1cb9ef
   151 
   151 
   152 
   152 
   153 deletes the element at index 1, i.e the second element of the
   153 deletes the element at index 1, i.e the second element of the
   154 list, 'eggs'. The other way is removing element by content. Lets say
   154 list, 'eggs'. The other way is removing element by content. Lets say
   155 one wishes to delete 100 from nonempty list the syntax of the command
   155 one wishes to delete 100 from nonempty list the syntax of the command
   156 should be 
   156 would be 
   157 
   157 
   158 .. #[[Anoop: let x = [1,2,1,3]
   158 .. #[[Anoop: let x = [1,2,1,3]
   159    	     now x.remove(x[2])
   159    	     now x.remove(x[2])
   160 	     still x is [2,1,3] so that is not the way to remove
   160 	     still x is [2,1,3] so that is not the way to remove
   161 	     element by index, it removed first occurrence of 1(by
   161 	     element by index, it removed first occurrence of 1(by
   176 
   176 
   177 If we check now we will see that the first occurence 'spam' is removed
   177 If we check now we will see that the first occurence 'spam' is removed
   178 thus remove removes the first occurence of the element in the sequence
   178 thus remove removes the first occurence of the element in the sequence
   179 and leaves others untouched.
   179 and leaves others untouched.
   180 
   180 
       
   181 One should remember this that while del removes by index number.
       
   182 Remove , removes on the basis of content being passed so if ::
       
   183        
       
   184        k = [1,2,1,3] 
       
   185        del([k[2])
       
   186 
       
   187 gives us [1,2,3]. ::
       
   188 
       
   189       k.remove(x[2])
       
   190 
       
   191 will give us [2,1,3]. Since it deletes the first occurence of what is
       
   192 returned by x[2] which is 1.      
       
   193 
       
   194 
       
   195 
   181 
   196 
   182 
   197 
   183 
   198 
   184 
   199 
   185 .. #[[Anoop: does it have two spams or two pythons?]]
   200 .. #[[Anoop: does it have two spams or two pythons?]]