Skip to content
Advertisement

Iterating through list of lists of lists

I am trying to iterate through a 3-D list in python(not numpy but I am willing to convert to a numpy array if this makes it easier) in such a way that from a list like this:

JavaScript

I can get the output

JavaScript

I can’t figure out how to make it iterate like this…

My code:

JavaScript

I’ve tried different things but can’t seem to get this output.

Advertisement

Answer

I think you want to print the nth sub-sublists consecutively from each sublist. You could unpack and zip a to get an iterable of tuples, then print each pair in them:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement