-
Notifications
You must be signed in to change notification settings - Fork 0
/
1arrays.py
62 lines (58 loc) · 1 KB
/
1arrays.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
cars = ["Ford", "Volvo", "BMW"]
for x in cars:
print(x)
cars.append("Honda")
print(cars)
cars.pop(1)
print(cars)
cars.remove("Honda")
print(cars)
cars.clear()
print(cars)
print()
cars = ["Ford", "Volvo", "BMW"]
x = cars.copy()
print(x)
print()
x = cars.count("Volvo")
print(x)
print()
y = [1, 2, 3]
cars.extend(y)
print(cars)
print()
x = cars.index("Volvo")
print(x)
print()
cars.insert(2, "Kia")
print(cars)
print()
cars.reverse()
print(cars)
print()
cars = ["Ford", "Volvo", "BMW"]
cars.sort()
print(cars)
cars.sort(reverse = True)
print()
def myfunc(i):
return(i)
cars = ["Ford", "Volvo", "BMW"]
cars.sort(key = myfunc)
print(cars)
print()
def myfunc(i):
return i['year']
cars = [
{'car' : 'Ford', 'year' : 2009},
{'car' : 'BMW', 'year' : 2003},
{'car' : "Volvo", "year" : 2011}
]
cars.sort(key = myfunc)
print(cars)
print()
def myfunc(i):
return(i)
cars = ["Ford", "Volvo", "BMW"]
cars.sort(reverse = True, key = myfunc)
print(cars)