Page 196 -
P. 196

list slicing




                                                 Have you not been drinking enough
                                                 water? I wanted the three fastest times
                                                for each athlete...but you’ve given me
                                                 everything and it contains duplicates!
































           In your haste to sanitize and sort your data, you forgot to worry about what
           you were actually supposed to be doing: producing the three fastest times for each
           athlete. And, of course, there’s no place for any duplicated times in your
           output.
          Accessing the first three data items from any list is easy. Either specify each list
           item individually using the standard notation or use a list slice:



                      Access each data item        james[0]
                      you need individually.       james[1]

                                                   james[2]
                                                                            Use a list slice to access from list

                                                   james[0:3]               item 0 up-to-but-not-including
                                                                            list item 3.


           But…what about removing duplicates from your list?


           160    Chapter 5
   191   192   193   194   195   196   197   198   199   200   201