-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry_except_lambda.py
More file actions
77 lines (62 loc) · 1.59 KB
/
Copy pathtry_except_lambda.py
File metadata and controls
77 lines (62 loc) · 1.59 KB
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
76
77
import re
def task_1():
L = []
Sum = 0
print("Введите длину списка:")
try:
n = int(input())
except:
print("Длина списка должна быть целым числом")
return 0
for i in range(n):
print("L[", i, "] = ", sep="", end="")
L.append(input())
for i in range(len(L)):
try:
Sum += int(L[i])
except ValueError:
Sum += -1
if Sum == -1 * len(L):
print("Элементы списка нельзя суммировать")
else:
print(Sum)
def foo(d):
d.update({'new_key':'with_map'})
return d
def task_2():
L = [{"Кот": "Фунтик"}, {"Питон": "Жизнь"}, {"Настя": "Солнышко ^^"}]
L = list(map(foo, L))
print(L)
def task_3():
a = [-1, 2, -3, 4, 5]
a = list(filter(lambda x: x > 0, a))
print(a)
def foo_in_task_4(a, b):
c = []
for i in range(len(a)):
if a[i] > b[i]:
c.append(0)
else:
c.append(1)
return c
def task_4(a, b):
return list(map(lambda x, y: 0 if x > y else 1, a, b))
def simple_generator(val):
while val > 0:
val = val / 2
yield val
def task_5():
gen_iter = simple_generator(100)
i = 10
while i > 0:
try:
print(next(gen_iter))
except StopIteration:
print("StopIteration")
return 0
def task_6():
str = "anf 17u fkjgktjg 123 gvbnn 81 jfjgj 12/n"
a = re.findall(r' 1\d*' , str)
print(list(map(lambda x: x.strip(), a)))
if __name__ == '__main__':
task_6()