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
# 1. There is a list of mac addresses - create a list of commands to delete this mac
# [‘aabbcc’, ‘a1b1c1’] -> [‘curl -X DELETE https://marina.ring.com/aabbcc’, ‘curl -X DELETE https://marina.ring.com/a1b1c1’]
mac_ids = ['aabbcc', 'a1b1c1']
commands = 'curl -X DELETE https://marina.ring.com/'
def replace_mac_id (list, command):
for mac in list:
print(f'1. Answer : {command}{mac}')
replace_mac_id(mac_ids, commands)
# OR
def replace_mac(list, command):
result_list = []
for mac in list:
com = command + mac
result_list.append(command)
print(f'1.1 Answer: {result_list}')
replace_mac(mac_ids, commands)
# 2. There is a string, for each letter return the position of last occurrence.
# ‘abracadabra’ -> {'a': 10, 'b': 8, 'r': 9, 'c': 4, 'd': 6}
letter_string = 'abracadabra'
letter_dict = {}
for x in letter_string:
letter_dict[x] = len(letter_string) - 1 - letter_string[::-1].index(x)
print(f'2. Answer: {letter_dict}')
# 2.*There is a list of integers, create a dict with count of each element (have a look at defaultdict)
# [1, 2, 4, 6, 2, 7, 1, 2, 1, 2, 2] -> {1: 3, 2:5, 4:1, 6:1, 7:1}
# 3. There is a list of integers, return count of even elements:
# [1, 2, 3, 4, 5, 6, 6, 6,7, 8, 22] -> 7
list_int = [1, 2, 3, 4, 5, 6, 6, 6,7, 8, 22]
count_even = 0
for x in list_int:
if x % 2 == 0:
count_even += 1
print(f'3. Answer: {count_even}')
# 4. There is a list of integers, return only those elements that can be divided by position index (add 0s)
# [0, 3, 3, 6, 12, 7, 4, 21, 0] -> [0, 3, 6,12, 21]
list_int_1 = [0, 3, 3, 6, 12, 12, 7, 4, 21]
list_only_div = []
i = 0
if list_int_1[0] == 0:
list_only_div.append(0)
for x in list_int_1[1:]:
i += 1
if x % i == 0:
list_only_div.append(x)
print(f'4. Answer: {list_only_div}')
# 5. Turn letters on even positions uppercase and on odd positions lowercase
# "quick BROWN fox JUMPS over THE lazy DOG" -> 'QuIcK BrOwN FoX JuMpS OvEr tHe lAzY DoG'
string = "quick BROWN fox JUMPS over THE lazy DOG"
result_string = ''
i = 0
for x in string:
if i % 2 == 0:
result_string += x.upper()
else:
result_string += x.lower()
i += 1
print(f'5. Answer : {result_string}')