-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay25.py
More file actions
78 lines (60 loc) · 1.48 KB
/
Day25.py
File metadata and controls
78 lines (60 loc) · 1.48 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# List Methods
# list.sort()
# This method sorts the list in ascending order. The original list is updated.
print("\nExample 1: List.sort()")
l = [1, 24, 34, 25, 65, 9]
print("The current list: ")
print(l)
print("The list after sorting: ")
l.sort()
print(l)
print("\nThe list in descending order: ")
l.sort(reverse=True)
print(l)
# Append : Adding an element at the back of a list
print("\nExample 2: List.append()")
l1 = [1, 4, 2, 5, 7, 3, 8]
print("The list is: \n", l1)
print("Adding an element at the end of list: ")
l1.append(10)
print(l1)
# Reverse
print("\nExample 3: List.reverse()")
print("The list is: \n", l)
l.reverse()
print("The reversed list is: \n", l)
# index
print("\nExample 4: List.index()")
# This method returns the index of the first occurrence of the list item
print("The list is : \n", l)
print(l.index(65))
# Count
print("\nExample 5: List.count()")
# Returns the count of the no. of with the given value.
print(l.count(65))
# Copy
# Returns copy of the list.
# This can be done to perform operations on the list without modifying the original list
print("\nExample 6: List.copy()")
m = l
m[0] = 0
print(l)
# This changes the original list, since m is a reference of l.
# so instead do this
m = l.copy()
m[0] = 0
print(l)
# Insert
print("\nExample 7: List.insert()")
print(l)
l.insert(1, 77)
print(l)
# Extend
print("\nExample 8: List.extend()")
m = [900, 100, 200]
l.extend(m)
print(l)
# Concatenate two list
print("\nExample 9: List concatenate")
k = l + m
print(k)