ex1 There is list of mac addresses create list of commands to delete t

 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
71
72
73
74
75
#ex1 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’]
list5 = ['aabbcc', 'a1b1c1']
list5 = list(filter(None, list5))
print (str(list5))
list5 = ' '.join(list5).split()
print (str(list5))
#ex2 There is a string, for each letter return the position of last occurrence.
string1 = 'abracadabra'
data = set(string1)
print(data)
for letter in data:
print(letter, string1.rfind(letter))
#ex2* There is a list of integers, create a dict with count of each element (have a look at defaultdict)
List3 = [1, 2, 4, 6, 2, 7, 1, 2, 1, 2, 2]
def CountFrequency(List3):
freq = {}
for item in List3:
if item in freq:
freq[item] += 1
else:
freq[item] = 1
for key, value in freq.items():
print('%d : %d' % (key, value))
if __name__ == '__main__':
CountFrequency(List3)
import collections
counter = collections.Counter(List3)
print(counter)
# ex 3 There is a list of integers, return count of even elements:
list1 = [1, 2, 3, 4, 5, 6, 6, 6, 7, 8, 22]
even_count, odd_count = 0, 0
for num in list1:
if num%2 == 0:
even_count += 1
else:
odd_count += 1
print (even_count)
# ex4 There is a list of integers, return only those elements that can be divided by position index (add 0s)
list2 = [0, 3, 3, 6, 12, 7, 4, 21]
result = {}
for ind, elem in enumerate (list2):
print(f'{elem}->{ind}')
result[elem] = ind
#какую команду написать, чтобы не я руками прописывала лист индексов???
#ex5 Turn letters on even positions uppercase and on odd positions lowercase
string2 = 'quick BROWN fox JUMPS over THE lazy DOG'
list4 = list()
for i, letter in enumerate (string2):
if i%2 == 0:
list4.append(letter.upper())
else:
list4.append(letter.lower())
print (''.join(list4))