Kostya There is list of mac addresses create list of commands to delet

 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
Kostya
# 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’]
macs = ['aabbcc', 'a1b1c1']
commands = []
for mac in macs:
commands.append('curl -X DELETE https://marina.ring.com/%s' %mac)
print(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}
str = 'abracadabra'
letters = ['a','b','r','c','d']
d = {}
for letter in letters:
position = len(str)-1 - str[::-1].index(letter)
d[letter] = position
print(d)
list = [1, 2, 4, 6, 2, 7, 1, 2, 1, 2, 2]
numbers = [1, 2, 4, 6, 7]
result = {}
for number in numbers:
result[number] = list.count(number)
print(result)
# There is a list of integers, return count of even elements:
# [1, 2, 3, 4, 5, 6, 6, 6,7, 8, 22] -> 7
list = [1, 2, 3, 4, 5, 6, 6, 6, 7, 8, 22]
counter = 0
for item in list:
if item %2 == 0:
counter += 1
print(counter)
# 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, 3, 6, 12, 21]
list = [0, 3, 3, 6, 12, 7, 4, 21]
result = []
result.append(list[0])
for i in range(1,len(list)):
if list[i] % i == 0:
print ('%s is divided to %s' %(list[i],i))
result.append(list[i])
print(result)
# 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'
sent = 'quick BROWN fox JUMPS over THE lazy DOG'
print(sent)
print(''.join([v.upper() if k % 2 == 0 else v.lower() for k, v in enumerate(sent)]))