I have an array which contains some elements.
How by doing arr[::-1]
sort the entire array?
What is the logic behind that?
I have an array which contains some elements.
How by doing arr[::-1]
sort the entire array?
What is the logic behind that?
This is extended slice syntax. It works by doing [begin:end:step] - by leaving begin and end off and specifying a step of -1, it reverses a string. Example:
>>> 'hello world'[::-1]
'dlrow olleh'
See also