Skip to content

Commit 5c2ca08

Browse files
authored
Clarify return value in reverse_array function
Updated docstring to clarify that the function returns the reversed list. Modified example usage to display the reversed array correctly.
1 parent bf62aff commit 5c2ca08

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎data_structures/arrays/reverse_array.py‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
In-place array reversal that also returns the list to the caller.
2+
In-place array reversal that also returns the reversed list to the caller.
33
This algorithm reverses the elements of a list without using extra space.
44
"""
55

@@ -35,11 +35,15 @@ def reverse_array(arr: list[Any]) -> list[Any]:
3535
>>> reverse_array([])
3636
[]
3737
>>> reverse_array(list(range(5)))
38-
[0, 1, 2, 3, 4]
38+
[4, 3, 2, 1, 0]
3939
>>> reverse_array(tuple(range(5)))
40-
[0, 1, 2, 3, 4]
40+
Traceback (most recent call last):
41+
...
42+
TypeError: 'tuple' object does not support item assignment
4143
>>> reverse_array(range(5))
42-
[0, 1, 2, 3, 4]
44+
Traceback (most recent call last):
45+
...
46+
TypeError: 'range' object does not support item assignment
4347
"""
4448
left = 0
4549
right = len(arr) - 1
@@ -64,6 +68,5 @@ def reverse_array(arr: list[Any]) -> list[Any]:
6468
# Example usage:
6569
print("\n--- Example Usage ---")
6670
sample_array = [10, 20, 30, 40, 50, 60]
67-
print(f"Original array: {sample_array}")
68-
reverse_array(sample_array)
69-
print(f"Reversed array: {sample_array}")
71+
print(f"{sample_array = }")
72+
print(f"{reverse_array(sample_array) = }")

0 commit comments

Comments
 (0)