-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path012-reverse.py
More file actions
26 lines (20 loc) · 796 Bytes
/
012-reverse.py
File metadata and controls
26 lines (20 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Get a reverse of list
---------------------
Input: (list) original list
Return: None
Output: list update the original lsit with the reversed elements
"""
# Original list
cars = ["Audi", "BMW", "Chrysler", "Dodge"]
print('Original list: {}'.format(cars))
# Using [::-1] slice operator to get back the reversed list
reverse_1 = cars[::-1]
print('\nReversed list (1): {}'.format(reverse_1))
# Reverse function does not have any return value.
# It updates the list with the reversed elements.
# reverse_2 is used for demonstration purpose
# since function is inplace, the "cars.reverse()" is enough to use
reverse_2 = cars.reverse()
print('\nReversed list (2): {}'.format(cars))
print('The return value of function is: {}'.format(reverse_2))