0

So I have a list that looks like this:

list_1 = [[1, 2, 3, 4,],
         [5, 6, 7, 8],
         [9, 10, 11, 12]]

What I want to do is traverse through it like a snake, so the output is:

1,2,3,4,8,12,11,10,9,5,6,7 (if you visualize that against the original list hopefully you'll see what I mean.

I have this, which somewhat works though the output is choppy:

print(list_1[0], list_1[1][-1], list_1[2][-1], list_1[2][-2::-1], list_1[1][0:3])

What I want to do is come up with something that's more sustainable/generic, in case the length of each list gets longer (or shorter) or the number of sub-lists grows etc...

I think I need some kind of loop to do this, but not sure how to go about doing it...

JD2775
  • 3,658
  • 7
  • 30
  • 52
  • 1
    will there always be only 3 sub arrays or can the the number of subarrays increase? – depperm Mar 06 '18 at 17:54
  • @depperm it could increase, or decrease. I see this is marked as duplicate, sorry. I couldn't find the similar question to this – JD2775 Mar 06 '18 at 18:10

0 Answers0