-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogram_8_List_Functions.py
More file actions
47 lines (32 loc) · 1.28 KB
/
program_8_List_Functions.py
File metadata and controls
47 lines (32 loc) · 1.28 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
# Create a list of state names
stateList1 = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California']
stateList2 = ['Colorado', 'Conneticut', 'Delaware', 'Florida', 'Georgia']
stateList3 = ['Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas']
# a function to print the functions of a list
def PrintListFunctions():
listFunctions = ['append', 'count', 'extend', 'index',
'insert', 'pop', 'remove', 'reverse', 'sort']
print('The functions that belong to a list are:')
for function in listFunctions :
print( function, ' ', end='' )
print()
def ShowListFunctions():
# tell Python that we want to be able to change these
# lists, even though they are not in this function
global stateList1, stateList2, stateList3
print('The first list is:', stateList1)
# Add a state to the first list
stateList1.append('Wyoming')
# remove a state
stateList1.remove('Alabama')
print('The list was changed:', stateList1)
print('The second list is:', stateList2)
# reverse a list
stateList2.reverse()
print('This list was reversed:', stateList2)
def main():
PrintListFunctions()
ShowListFunctions()
# This tells Python to run the function called main()
if __name__ == "__main__":
main()