Head first python

Page 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, Terry Jones & Terry Gilliam, 91 mins Graham Chapman Michael Palin, John Cleese, Terry Gilliam, Eric Idle & Terry Jones

Another inner (inner), nested list

An inner, nested list

Your code

Process the outer, enclosing list.

Process the in nested list. ner,

for each_item in movies: if isinstance(each_item, list):

Yeah.. that’s almost working...it’s just a pity about that list of 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


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.