Page 198 -
P. 198

top three




                              Assume that the fourth from last line of code from your current program is changed to this:
                                     james = sorted([sanitize(t) for t in james])

                             That is, instead of printing the sanitized and sorted data for James to the screen, this line of
                              code replaces James’s unordered and non-uniform data with the sorted, sanitized copy.
                             Your next task was to write some code to remove any duplicates from the james list produced
                              by the preceding line of code. You were to start by creating a new list called unique_james
                              and then populate it with the unique data items found in james. Additionally, you were to
                              provide code to only display the top three fastest times for James.


                 Create the
                 empty list to     unique_james = []
                 hold the unique
                 data items.                             Iterate over the

                                    for each_t in james:  existing data…  …and if the data item ISN’T
                                           if each_t not in unique_james:  already in the new list…

                                                 unique_james.append(each_t)  …append the unique data item to
                                                                             the new list.



               Slice the first
               three data items
               from the list and     print(unique_james[0:3])
               display them on
               screen.









                                                            Do this!





                                               Repeat the code on this page
                                               for the rest of the coach’s lists:
                                              julie, mikey & sarah. Add
                                               all of your new code to your
                                               existing program.


           162    Chapter 5
   193   194   195   196   197   198   199   200   201   202   203