Jump to content


chaddow

Member Since 27 Sep 2014
Offline Last Active Sep 28 2014 07:10 AM
-----

Posts I've Made

In Topic: Chp1 Nesting Issue

28 September 2014 - 07:10 AM

Figured it out.

In Topic: Chp1 Nesting Issue

27 September 2014 - 09:56 AM

I tried re-entering movies and the code starting back on page 21, but am not getting a similar output as the book shows. Below is the code and results.

>>> movies = ["The Holy Grail", 1975, "Terry Jones & Terry Gilliam", 91, ["Graham Chapman", ["Michael Palin", "John Cleese", "Terry Gilliam", "Eric Idle", "Terry Jones"]]]
>>> print(movies)
['The Holy Grail', 1975, 'Terry Jones & Terry Gilliam', 91, ['Graham Chapman', ['Michael Palin', 'John Cleese', 'Terry Gilliam', 'Eric Idle', 'Terry Jones']]]
>>> for each_item in movies:
	print(each_item)

	
The Holy Grail
1975
Terry Jones & Terry Gilliam
91
['Graham Chapman', ['Michael Palin', 'John Cleese', 'Terry Gilliam', 'Eric Idle', 'Terry Jones']]
>>> for each_item in movies:
	if isinstance(each_item, list):
		for nested_item in each_item:
			print(nested_item)
		else:
			print(each_item)

			
Graham Chapman
['Michael Palin', 'John Cleese', 'Terry Gilliam', 'Eric Idle', 'Terry Jones']
['Graham Chapman', ['Michael Palin', 'John Cleese', 'Terry Gilliam', 'Eric Idle', 'Terry Jones']]
>>> 

Any advice would be helpful.

Thanks!