Reverse Python Sequence with s[::-1]

Want to reverse a #Python sequence (string/list/tuple)? Use a 3-argument slice: s[::-1] This works because: - Empty start means "from the start" - Empty end means "through the end" - Step size of -1 means "go back 1 each time" This returns a new value, from s's end to its start.

What's the performance compared to reversed(...) or list.reverse() (inplace)?

Like
Reply

To view or add a comment, sign in

Explore content categories