-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.py
More file actions
49 lines (36 loc) · 960 Bytes
/
Copy pathlist.py
File metadata and controls
49 lines (36 loc) · 960 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
names = ['ahmed', 'abdi', 'ali', 'yussuf', 'ali']
# Looping the array
for name in names:
print(name)
# first element
print(names[0])
# Last element
print(names[-1])
# Length of the list/array
print(len(names))
# List methods
# append() - adds an element to the list at the end
names.append("mohamed")
print(names)
# clear() - clears the list
# names.clear()
# print(names)
# count() - it returns the number of times an element appears in the list
print(names.count("ali"))
# insert - it adds an element to list at a specified index
names.insert(2, "amina")
print(names)
# index - returns the first occurence of the element
print(names.index("ali"))
# pop - removes an element a specified position/index
names.pop(3)
print(names)
# remove - removes the item with the specified value
names.remove("yussuf")
print(names)
# reverse - it reverses the order of the list
names.reverse()
print(names)
# sort - sorts the list
names.sort()
print(names)