-
Notifications
You must be signed in to change notification settings - Fork 0
/
lists.py
44 lines (29 loc) · 869 Bytes
/
lists.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
# Examples of Python lists
# A list is defined using the [] (Square) brackets.
# Individual items are seperated by commas.
my_shopping_list = ["Apples","Oranges","Milk", "Bread"]
print("="*20)
print("The list: ")
print("="*20)
print(my_shopping_list)
raw_input("\nPress Enter to advance...")
# We can add items to the list using the .append method
my_shopping_list.append("Butter")
print("="*20)
print("Added Butter: ")
print("="*20)
print(my_shopping_list)
# And we can remove items too - defaults to last item in list.
my_shopping_list.pop()
raw_input("\nPress Enter to advance...")
print("="*20)
print("Removed Butter: ")
print("="*20)
print(my_shopping_list)
# Let's sort the items into alphabetical order
my_shopping_list.sort()
raw_input("\nPress Enter to advance...")
print("="*20)
print("Sorted the list: ")
print("="*20)
print(my_shopping_list)