-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.py
More file actions
46 lines (25 loc) · 794 Bytes
/
lists.py
File metadata and controls
46 lines (25 loc) · 794 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
#A list is a changeable and ordered collection of data. Allows duplicate members.
numbers = [1, 2, 3, 4, 5]
alphas = ['a', 'b', 'c', 'd', 'e', 'abdul', 'banana', 'mangoes']
#print a specific data from a list
print(alphas[7])
#Get length of a list
print(len(alphas))
# add to the list
alphas.append('added')
#remove from list
alphas.remove('d')
#insert to list to a specific location
numbers.insert(2, 15)
#delete from list on a specific location
numbers.pop(0)
#reverse list
alphas.reverse()
# sort values; this will arrange your itmes alphabetically or in accending order
alphas.sort()
# Reverse sort values; this will arrange your itmes alphabetically but in deccending order
alphas.sort(reverse=True)
# change a value
alphas[2] = 'blueberry'
print(alphas)
print(numbers)