Page 59 -
P. 59

meet python


           Complex data is hard to process


           The movie buff’s data is complex. Let’s take another look at a subset of the
           data and your Python code that processes it.

                               The outer, enclosing list
             The data


                            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


                                                                    Another inner (inner), nested list
                               An inner, nested list

       Your code                                           Process the inner,
                   Process the outer, enclosing list.     nested list.


                                                                             Yeah.. that’s almost
                                                                             working...it’s just a
               for each_item in movies:                                      pity about that list of
                      if isinstance(each_item, list):                         supporting actors...
                            for nested_item in each_item:
                                   print(nested_item)
                      else:
                            print(each_item)












              Can you spot the problem with your Python
              code as it is currently written? What do you
              think needs to happen to your code to allow it to
              process the movie buff’s data correctly?




                                                                                       you are here 4    23
   54   55   56   57   58   59   60   61   62   63   64