-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.py
More file actions
65 lines (46 loc) · 1.03 KB
/
lists.py
File metadata and controls
65 lines (46 loc) · 1.03 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
animals = ["cat", "dog", "rabbit", "parrot"]
print(animals)
fruits = [["tomatoes", "oranges"], "apple", "banana", "cherry"]
print(fruits[0][1])
# Replace the second item
fruits[1] = "mango"
print(fruits)
animals.sort()
print(animals)
# Sort the list in descending order
numbers = [9, 1, 4, 7, 3]
numbers.sort()
print(numbers)
# Delete an item from the list
del numbers[1]
print(numbers)
# Delete the entire list
del numbers
# Insert an item at a given position
animals.insert(2, "tiger")
print(animals)
# Append an item to the end of the list
animals.append("lion")
print(animals)
# Remove the first item from the list whose value is x
animals.remove("cat")
print(animals)
# Reverse the elements of the list in place
animals.reverse()
print(animals)
fruits = ["apple", "banana", "cherry"]
print(fruits)
fruits[1] = "grapes"
print(fruits)
fruits.insert(1, "orange")
print(fruits)
fruits.sort()
print(fruits)
fruits.append("mango")
print(fruits)
fruits.reverse()
print(fruits)
fruits.remove("mango")
print(fruits)
fruits.pop()
print(fruits)