Today I teach students, we often use the list in python to flip, so how to reverse it?

The common ones are as follows:

list(original) = [0,1,2,3,4,5]

After inversion----------------------------------------------- --------------

list(flip) = [5,4,3,2,1,0]

Isn't it simple? upside down


picture

picture


Why do you want to wash your hair upside down?

Think of a way, put the head on the tail, put the tail on the head, and that's it


picture

The effect of the idea is as above. This is an even number of lists. How can the odd numbers be adjusted? The one in the middle doesn't move, I'm such a little genius... Open the whole thing!

The effect is as follows:


picture

picture


Sure enough

But I feel that something is missing. I feel that our code can be optimized. Do we have to give him a middle ground, do it synchronously... Start thinking

picture

I don't know about other codes, but python can do it!

picture

picture

ok!

 Is this the end?

 No, no, let's think more about it... idea

picture

Put the tail to head value in reverse, into the new list

Add append, then how to extract, traverse and extract from the tail index from large to small?

 ! After the pop is deleted, the value can be returned. How to use pop and how to use the index parameter

picture

The last one is deleted by default, so every time you delete the last one of the index, you can achieve the purpose of reversal without adding it to the new list! ?

accomplish....


picture

picture

Hmm, have you lost your studies?

- Video recommendation- 

Micro Sweet Software Test

- Scan the QR code for more information- 
picture
Weitian WeChat public account
picture
Micro Sweet Tencent Classroom
picture
Weitian video number
picture

Weitian official b station

picture
Slightly sweet vibrato official account
picture
Slightly sweet vibrato ip number