-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlists.py
More file actions
50 lines (36 loc) · 784 Bytes
/
lists.py
File metadata and controls
50 lines (36 loc) · 784 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
47
48
49
50
# list allows duplicate members..
# Create List
numbers = [1,2,3,4,5]
fruits = ['Pomengranate','Oranges','Peach']
# Use a constructor
numbers_cons = list((1,2,3,4,5))
print(numbers,numbers_cons)
# Get a value
print(fruits[1])
# Get Length
print(len(fruits))
# Append to list
fruits.append('Mangoes')
print(fruits)
# Insert into position
index = 2
new_fruit = 'Strawberries'
fruits.insert(index,new_fruit)
print(fruits)
# Remove from list
fruits.remove('Peach')
print(fruits)
# Change value
fruits[0] = 'Blueberries'
# Remove from position
fruits.pop(index)
print(fruits)
# Reverse the members..
fruits.reverse()
print(fruits)
# Sort list
fruits.sort()
print(fruits)
# Reverse sort
fruits.sort(reverse=False)
print(fruits)