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
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
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:
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
I don't know about other codes, but python can do it!
ok!
Is this the end?
No, no, let's think more about it... idea
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
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....
Hmm, have you lost your studies?
- Video recommendation-
Weitian official b station