![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | julkip |
I have an array over which I have to iterate forwards and backwards, depending on circumstances.
Is there a better way than just to use
var array = ["A", "B", "C", "D"]
var array_backwards = ["D", "C", "B", "A"]
and use each array accordingly? My first instinct was to use the invert()
function, but I saw that this does not return the array inverted, but inverts it in place. I guess I could probably use array.duplicate().invert()
instead of declaring it by hand, but this also seems a bit clunky to me.
You can do this by using an index and inverting the step:
for i in range(10, 0, -1):
print(i)
But that prints:
10
9
8
7
6
5
4
3
2
1
So either range(9, -1, -1)
or use i-1
?
Zylann | 2019-08-06 19:23