python - Flipped an array and reversing every second row -


basically have matrix in python 'example' (although larger). need product array 'example_what_i_want' python code. guess loop in order- how can this?

example=  [1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15], [16,17,18,19,20], [21,22,23,24,25]  example_what_i_want =  [25,24,23,22,21], [16,17,18,19,20], [15,14,13,12,11], [6,7,8,9,10], [5,4,3,2,1] 

so increments in kind of snake fashion. , first row must reversed! , follow pattern.

thanks!

i'm assuming example actually:

example = [[1,2,3,4,5],            [6,7,8,9,10],            [11,12,13,14,15],            [16,17,18,19,20],            [21,22,23,24,25]] 

in case do:

swapped_example = [sublst if idx%2 else sublst[::-1]                    idx,sublst in enumerate(example)][::-1] 

which give you:

in [5]: swapped_example out[5]:  [[25, 24, 23, 22, 21],  [16, 17, 18, 19, 20],  [15, 14, 13, 12, 11],  [6, 7, 8, 9, 10],  [5, 4, 3, 2, 1]] 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -