在Go中反转切片顺序的惯用方式(不是降序排序)? [重复]

This question already has an answer here:

Is there an elegant or idiomatic go way of returning the reverse order of a slice? I'm not talking about getting the descending order as was the answer in a similarly asked question here: How do I reverse sort a slice of integer Go?

Example, given an array:

arr := []int{2, 5, 7, 1}

I want a slice with the following output:

[1 7 5 2]

I know one approach would be to use a for loop but I was wondering if there was a more efficient solution.

Coming from python, one easy and great solution would be using slicing by doing something like:

arr[::-1]

But go doesn't operate like that so that's why I'm looking for a comparable version of that in go.

</div>

Is there an elegant or idiomatic go way of returning the reverse order of a slice?

No.

You have to switch elements.