Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

Thanks to everyone contributing to this repository!

- [Your Name Here]
- [Your Name Here]
- Shrihari Bhilwadikar
23 changes: 23 additions & 0 deletions reverse_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Reverses an array in Python using simple methods

# Example array
arr = [1, 2, 3, 4, 5]
print("Original array:", arr)

# Using slicing
reversed_arr = arr[::-1]
print("Reversed array (slicing):", reversed_arr)

# Using reverse() method
arr_copy = arr.copy() # make a copy to keep original intact
arr_copy.reverse()
print("Reversed array (reverse method):", arr_copy)

# Manual swapping
manual_arr = arr.copy()
start, end = 0, len(manual_arr) - 1
while start < end:
manual_arr[start], manual_arr[end] = manual_arr[end], manual_arr[start]
start += 1
end -= 1
print("Reversed array (manual swap):", manual_arr)