Slide 50
Slide 50 text
Lists (contd.)
• We can append, manipulate and delete items from a list
1 l = [ ”one” , ”two” , ” three ” ]
# Remove the f i r s t element with VALUE one
3 l . remove (”one”)
# [” two” , ” three ”]
5 # Remove the element at index 1
del l [ 1 ]
7 # [” two ”]
# Append to the end of the l i s t
9 l . append (” four ”)
# [” two” , ” four ”]
11 # Append at a s p e c i f i c posit ion
l . i n s e r t (0 , ” s i x ”)
13 # [” s i x ” , ”two” , ” four ”]
# L i s t s can contain duplicates (more on t h i s l a t e r )
15 l = [1 , 2 , 3]
l . append (1)
17 # [1 ,2 ,3 ,1]
28