There is list of mac addresses create list of commands to delete this

 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
66
67
68
69
70
1. There is a list of mac addresses - create a list of commands to delete this mac
macs = ['aabbcc', 'a1b1c1', 'f8369b4af896', '74daead5d08a', 'f8369b4af04f', 'f8369b48d599', '94e36d937428', '6847492710ed']
for mac in macs:
if mac == 'a1b1c1' or mac == 'aabbcc':
print(f'The fake macs are found and will be deleted : {mac}')
macs.remove(mac)
#Note : Don't understand why after I add command .remove, the output changes and it shows onlu one mac instead of two
if to remove this command, the output will show both macs.
2.There is a string, for each letter return the position of last occurrence.
a = 'abracadabra'
print(f' last position of a is {a.rfind("a")}')
print(f' last position of b is {a.rfind("b")}')
print(f' last position of r is {a.rfind("r")}')
print(f' last position of c is {a.rfind("c")}')
print(f' last position of d is {a.rfind("d")}')
#or
target = "c"
last_pos = len(a) - 1 - a[::-1].index(target)
print(last_pos)
#Note I got issues understanding default dict
2*
a = [1, 2, 4, 6, 2, 7, 1, 2, 1, 2, 2]
from collections import Counter
r = Counter(a)
print(r)
3. There is a list of integers, return count of even elements:
d = [1, 2, 3, 4, 5, 6, 6, 6,7, 8, 22]
count = 0
for e in d:
if e % 2 == 0:
count += 1
print(count)
#Note: I got issues converting the output(int) into the list to count it as I used to, need some explenations
4. There is a list of integers, return only those elements that can be divided by position index (add 0s)
a = [0, 3, 3, 6, 12, 7, 4, 21]
for (i,e) in enumerate(a):
if i == 0 or i != 0 and e % i == 0:
print(e)
5. Turn letters on even positions uppercase and on odd positions lowercase
a = "quick BROWN fox JUMPS over THE lazy DOG"
result = []
for i,e in enumerate(a):
if i % 2 == 0:
result.append(e.upper())
else:
result.append(e.lower())
print(''.join(result))
# Аж самому понравилось решение