-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.py
More file actions
91 lines (71 loc) · 1.9 KB
/
list.py
File metadata and controls
91 lines (71 loc) · 1.9 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
79
80
81
82
83
84
85
86
87
88
89
90
91
# ***************************************************************
# Name : list program
# Author: Than Tong
# Created : * Course: CIS189
# Version: 1.0
# OS: Windows 11
# IDE: Python
# Copyright : This is my own original work
# based onspecifications issued by our instructor
# Description :
# Input: ADD HERE XXX
# Ouput: ADD HERE XXX
# Academic Honesty: I attest that this is my original work.
# I have not used unauthorized source code, either modified or
# unmodified. I have not given other fellow student(s) access
# to my program.
# Create the list
list_one = ['the', 'big', 'dog']
print(list_one)
# append another string to the list
list_one.append('pig')
# print the new list
print(list_one)
# copy the list to another list
list_two = list_one.copy()
# print both lists
print("list One: ")
print(list_one)
print("List two: ")
print(list_two)
# get string at index 2
print("String at index 2: ")
print(list_one[2])
# first add dog 3 times to the list
list_one.append('dog')
list_one.append('dog')
list_one.append('dog')
# print the list
print("List one: ")
print(list_one)
# count the number of times dog is in the list
print("Number of times dog is in the list: ")
print(list_one.count('dog'))
# print the list
print("List one: ")
print(list_one)
# insert a string at index 2
list_one.insert(2, 'fox')
# print the list
print("List one after inserting fox: ")
print(list_one)
# remove the string at index 2
list_one.remove('fox')
# print the list
print("List one after removing fox: ")
print(list_one)
# reverse the list
list_one.reverse()
# print the list
print("List one after reversing: ")
print(list_one)
# sort the list
list_one.sort()
# print the list
print("List one after sorting: ")
print(list_one)
# clear the list
list_one.clear()
# print the list
print("List one after clearing: ")
print(list_one)