-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlists_exercise.py
117 lines (94 loc) · 4.26 KB
/
lists_exercise.py
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
my_friends = ["Joseph", "Glenn", "Sally"]
print(my_friends[0])
print(my_friends[1])
print(my_friends[2])
print(f"Hi, {my_friends[0]} how are you doing ?")
print(f"Wozaa, {my_friends[1]} i was wondering if you could help me with something ?")
print(f"Hello, beautiful {my_friends[2]} i have missed you so much.")
music = ["Rnb" ,"AfroBeat" ,"Reggae" ,"Hip-pop" ,"Gospel"]
print(f"My favorite {music[1]} song is YAWA by Fireboy DML")
dinner_friends = ["Joseph", "Glenn", "Sally"]
print(f"Hi, {dinner_friends[0]} would you like to come over for dinner ?")
print(f"Hi, {dinner_friends[1]} there is a new movie out, would you like to come over and watch it ?")
print(f"Hi beautiful {dinner_friends[2]} i have missed you so much, would you like to come over for dinner ?")
dinner_friends = ["Joseph", "Glenn", "Sally"]
not_coming = dinner_friends.pop(0)
print(f"Unfortunately {not_coming} wont be able to make to dinner.")
dinner_friends.insert(0 ,"Maggy")
print(dinner_friends)
print(f"Hi, {dinner_friends[0]} i would like to invite you to dinner.")
print(f"Hi, {dinner_friends[1]} i would like to invite you to dinner.")
print(f"Hi {dinner_friends[2]} i would like to invite you to dinner.")
print(dinner_friends)
dinner_friends.insert( 0 ,"Juliet")
dinner_friends.insert(2,"Vivian")
dinner_friends.append("Linda")
print(dinner_friends)
print(f"Hi, {dinner_friends[0]} i would like to invite you to dinner.")
print(f"Hi, {dinner_friends[1]} i would like to invite you to dinner.")
print(f"Hi, {dinner_friends[2]} i would like to invite you to dinner.")
print(f"Hi, {dinner_friends[3]} i would like to invite you to dinner.")
print(f"Hi, {dinner_friends[4]} i would like to invite you to dinner.")
print(f"Hi, {dinner_friends[5]} i would like to invite you to dinner.")
print(dinner_friends)
print("You can only invite two people for dinner")
not_inviting = dinner_friends.pop()
print(f"Sorry {not_inviting} i wont be able to invite you ")
not_inviting = dinner_friends.pop()
print(f"Sorry {not_inviting} i wont be able to invite you")
not_inviting = dinner_friends.pop()
print(f"Sorry {not_inviting} i wont be able to invite you")
not_inviting = dinner_friends.pop()
print(f"Sorry {not_inviting} i wont be able to invite you")
print(dinner_friends)
print(f"Hi {dinner_friends[0]} you are still invited to dinner")
print(f"Hi {dinner_friends[1]} you are still invited to dinner")
print(dinner_friends)
del dinner_friends[-2:] #deleting the last 2 items in the list
print(dinner_friends)
dream_destination = ["Maldives" ,"San Francisco" ,"New York" ,"Paris" ,"London" ]
print(dream_destination)
sorted_destination = sorted(dream_destination)
print(f"This is the sorted destination:\n {sorted_destination} \nwithout modifying the actual list : \n{dream_destination}")
dream_destination = ["Maldives" ,"San Francisco" ,"New York" ,"Paris" ,"London" ]
sorted_destination = sorted(dream_destination, reverse=True)
print(f"This is sorted order alphabetically: {sorted_destination} and this is my original list: {dream_destination}")
#change order of list
dream_destination = ["Maldives" ,"San Francisco" ,"New York" ,"Paris" ,"London" ]
dream_destination.reverse()
print(dream_destination)
#revert back to original order
dream_destination = ["Maldives" ,"San Francisco" ,"New York" ,"Paris" ,"London" ]
dream_destination.reverse()
print(dream_destination)
dream_destination = ["Maldives" ,"San Francisco" ,"New York" ,"Paris" ,"London" ]
dream_destination.sort()
print(dream_destination)
dream_destination = ["Maldives" ,"San Francisco" ,"New York" ,"Paris" ,"London" ]
dream_destination.sort(reverse = True)
print(dream_destination)
dinner_friends = ["Joseph", "Glenn", "Sally"]
number_of_invites = len(dinner_friends)
print(f"The number of friends invited for dinner is {number_of_invites}")
counties = []
counties.append("Nairobi")
counties.append("Mombasa")
counties.append("Kisumu")
counties.append("Nakuru")
counties.append("Kakamega")
print(counties)
length_of_counties =len(counties)
print(length_of_counties)
print(counties)
counties.insert(0, "Kisii")
print(counties)
counties.pop()
print(counties)
counties.remove("Nakuru")
print(counties)
counties = ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Kakamega"]
del counties[-5:]
print(counties)
counties = ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Kakamega"]
counties.sort()
print(counties)