Skip to content

Commit 7995b9d

Browse files
author
majid shahbaz
committed
Added list methods implementations
1 parent 6123219 commit 7995b9d

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/datastructures/lists/list.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,45 @@
11
# LISTS
22
"""
33
To check the detail about list please refer to README.md in the same list folder
4-
"""
4+
"""
5+
# Create an empty list
6+
7+
empty_list = []
8+
9+
# Create a non-empty list
10+
non_empty_list = [1,2,3]
11+
12+
# Print a list
13+
14+
print(non_empty_list)
15+
# [1, 2, 3]
16+
17+
# Add a element in the predefined list using append
18+
19+
non_empty_list.append(4)
20+
empty_list.append(5)
21+
print(empty_list)
22+
# prints -> [5]
23+
print(non_empty_list)
24+
# [1, 2, 3, 4]
25+
26+
# Add elements of empty list to non_empty list using extend
27+
non_empty_list.extend(empty_list)
28+
print(non_empty_list)
29+
# prints -> [1, 2, 3, 4, 5]
30+
31+
# insert a element at specific index
32+
non_empty_list.insert(0,0)
33+
print(non_empty_list)
34+
# prints -> [0, 1, 2, 3, 4, 5]
35+
36+
# Remove a element from list (Remove first element from list that will be searched)
37+
non_empty_list.remove(5)
38+
print(non_empty_list)
39+
# prints -> [0, 1, 2, 3, 4]
40+
41+
# Pop the last element from the list
42+
non_empty_list.pop()
43+
print(non_empty_list)
44+
# Prints -> [0, 1, 2, 3]
45+

0 commit comments

Comments
 (0)