Page 42 -
P. 42

dealing with data


           Deal with complex data


          Any program of any worth that you create has to work with data. Sometimes,
           the data is simple and straightforward—easy to work with. Other times, the
           data you have to work with is complex in its structure and meaning, forcing you
           to work hard to make sense of it all, let alone write code to process it.
           To tame complexity, you can often arrange your data as a list: there’s the list
           of customers, your friend’s list, the shopping list, and your to-do list (to name
           a few). Arranging data in lists is so common that Python makes it easy for you
           to create and process lists in code.
           Let’s look at some complex data before learning how to create and process list
           data with Python.

                                             I’ve been making lists of
                                             movie data for years and
            A highly                         would love to be able to
            organized                        process it on my laptop...                   There sure is
                                                                                          a lot of data
             movie buff                                                                   listed here.




                      The Holy Grail, 1975, T erry Jones & T erry Gilliam, 91 mins
                             Graham Chapman

                      Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones  The Holy Grail, 1975, T erry Jones & T erry Gilliam, 91 mins
                      The Life of Brian, 1979, T erry Jones, 94 mins
                             Graham Chapman

                      Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones     Graham Chapman
                      The Meaning of Life, 1983, T erry Jones, 107 mins
                             The six Monty Python cast members
                      The Holy Grail, 1975, T erry Jones & T erry Gilliam, 91 mins
                             Graham Chapman                        Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones

                      Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones
                      The Life of Brian, 1979, T erry Jones, 94 mins
                             Graham Chapman         The Life of Brian, 1979, T erry Jones, 94 mins

                        Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones
                      The Meaning of Life, 1983, T erry Jones, 107 mins
                             The six Monty Python cast members     Graham Chapman
                      The Holy Grail, 1975, T erry Jones & T erry Gilliam, 91 mins
                             Graham Chapman
                                                                  Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones
                      Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones
                      The Life of Brian, 1979, T erry Jones, 94 mins
                             Graham Chapman

                        Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones  The Meaning of Life, 1983, T erry Jones, 107 mins
                      The Meaning of Life, 1983, T erry Jones, 107 mins
                             The six Monty Python cast members
                                                           The six Monty Python cast members
                                                                  Graham Chapman, Michael Palin, John Cleese, T erry Gilliam, Eric Idle & T erry Jones
                                                                         This data is complex, too.
           On first glance, this collection of data does indeed look quite complex.
           However, the data appears to conform to some sort of structure: there’s a line
           for a list of basic movie facts, then another line for the lead actor(s), followed
           by a third line listing the movie’s supporting actors.
           This looks like a structure you can work with…
           6    Chapter 1
   37   38   39   40   41   42   43   44   45   46   47