Skip to content

Commit 9ff5e49

Browse files
Create Python_list_operations.py
1 parent a1b1366 commit 9ff5e49

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Python_list_operations.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Traverse a Python list in reverse order
2+
# Using iterate list elements and
3+
# insert() method
4+
5+
# Define a list
6+
list1 = [10, 20, 30, 40, 50]
7+
8+
# Print the list
9+
print("Original list: ", list1)
10+
11+
# Create a new list with elements
12+
# in reverse order
13+
newlist = [] # an empty list
14+
for item in list1:
15+
newlist.insert(0, item)
16+
17+
# Print the new list
18+
print("List in reverse order:",newlist)

0 commit comments

Comments
 (0)