x = [0, None] y = ["abc", 1] s = (any(x), any(y)) == (all(x), all(y)) print(s)
Задачи по питону и машинному обучению: алгоритмы, функции, классы, регулярные выражения, итераторы, генераторы, ООП, исключения, numpy, pandas, matplotlib, scikit-learn, TensorFlow и др. #Python #ml
x = [0, None] y = ["abc", 1] s = (any(x), any(y)) == (all(x), all(y)) print(s)
x = [0, None, 1] y = [] s = (any(x), any(y)) == (all(y), all(x)) print(s)
s = [1, 2, 1, 1, 1, 3] print(s.count(1) + s.index(2))
s = [1, 2, 1] print(s.index(1), s.index(2))
a = "Xmas" b = a a = "New Year" print((a is b))
s = [1, 2, 3] s.append(3) s = list(sorted(set(s))) s.pop() s.remove(1) print(*s)
s = [1, 2, 3, 4] s.insert(2, 100) del s[:2] s.pop() s.remove(3) print(*s)
def f():
yield 0
yield from [1, 2]
yield 3
print(*f())values = [8, 3, 1]
group = {2, 7}
def f(values, group):
count = 0
def g(x):
nonlocal count
if x in group:
count += 1
return (0, x)
return(1, x)
values.sort(key=g)
return count
count = f(values, group)
print(count)def f(x):
if x in group:
return (0, x)
return (1, x)
group = {5, 6, 7}
values = {4, 9, 7, 8, 3, 5}
print(*sorted(values, key=f))a, b = 1, 0
def divide1(a, b):
try:
return a / b
except ZeroDivisionError:
return None
def divide2(a, b):
try:
return True, a / b
except ZeroDivisionError:
return False, None
print(divide1(a, b), *divide2(a, b))s = 0
try:
s += 1/0
except ZeroDivisionError:
s += 1
else:
s += 5
finally:
s += 10
print(s)from itertools import zip_longest x = [1, 2, 3] y = ["a", "b"] l = list(zip(x, y)) m = list(zip_longest(x, y)) print(l == m)
sum(x[0] for x in enumerate(range(2), 5))
x = [[y**x for y in range(1, 3)] for x in range(1, 3)] print(x)