Embedded For Loop With No Data

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Fri Jul 6 00:50:36 CEST 2007

On Thu, 05 Jul 2007 22:03:59 +0000, rshepard wrote:

>   Haven't found an answer to my question in the books and other docs I have
> available, so I am asking here.
>   I have three lists of data retrieved from database tables. I want to cycle
> through all three lists using nested FOR loops. What is the behavior if
> there are no data in the list used in the middle loop?

Why don't you try it and see for yourself?

types = ["Type A", "Type B", "Type C"]
subtypes = []
details = [1, 2, 3]

>   Example:
>   for a in types:
>       for b in subtypes:
>           for c in details:
> 		do some processing
>   Not every item in the 'types' list will have an associated 'subtype'. Does
> the index ignore that loop and drop to the one nested beneath it?

Be sure to write back and let us know what you discover.


More information about the Python-list mailing list