Останнє ДЗ

 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
# 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’]
a = ['aabbcc', 'a1b1c1']
b = 'curl -X DELETE https://marina.ring.com/'
c = [i + b for i in a]
print(c)
# 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}
def count_num(x):
res = {}
for k, v in enumerate(x):
if v not in res:
res[v] = len([k])
else:
res[v] += len([k])
return res
a = [1, 2, 4, 6, 2, 7, 1, 2, 1, 2, 2]
print(count_num(a))
# 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'
e = 'quick BROWN fox JUMPS over THE lazy DOG'
def low_up(p):
for i,c in enumerate(p):
if i % 2 == 0:
return c.upper()
else:
return c.lower()
print(low_up(e))
#проходить першу ітерацію, і виконується умова "якщо" і видає результат лише першу букву. Залишилось лише придумати, як зробити так, щоб проходило всі значення