reversing a subarray

🏠

Say you have the following array:

1 A = [0,1,2,3,4,5,6,7,8,9]

How would you reverse the subarray from index 3 to 6 inclusive?

Solution:

1 A = [0,1,2,3,4,5,6,7,8,9]
2 A[3:7] = reversed(A[3:7])
3 print(A)

Output:

1 [0, 1, 2, 6, 5, 4, 3, 7, 8, 9]