from functools import reduce y = reduce(lambda a, b: a + b , [1, 2, 3, 4]) print(y)
Задачи по питону и машинному обучению: алгоритмы, функции, классы, регулярные выражения, итераторы, генераторы, ООП, исключения, numpy, pandas, matplotlib, scikit-learn, TensorFlow и др. #Python #ml
from functools import reduce y = reduce(lambda a, b: a + b , [1, 2, 3, 4]) print(y)
def f():
import sys
locs = sys._getframe(1).f_locals
setattr(locs['self'], 'xy', 4*locs['x'] + 7*locs['y'])
class A:
def __init__(self, x, y):
self.xy = 2*x + 3*y
f()
a = A(2, 3)
A.xy = 99
print(a.xy)def f(x):
if x < 3:
return x
y = filter(f, (0, 1, 2, 3, 4))
print(list(y))def func(x):
if x >= 3:
return x
y = filter(func, (1, 2, 3, 4))
print(list(y))x = 5 print([y%2 for y in range(6)][x])
tup = (5, 7, 22, 97) newtup = tuple(map(lambda x: x + 3, tup)) print(newtup)
def f(p, q):
return p + q
x = list(map(f, ('a', 'b', 'c'), ('x', 'y', 'z')))
print(x[1])s = list(map(lambda x, y: x + y, [1, 2, 3], [4, 5, 6])) print(s)
s = list(map(lambda x: x * x, (1, 2, 3, 4))) print(s)
name = {
124: "A",
444: "B",
952: "C"}
user_id = 375
print(name.get(user_id, "D"))print((lambda x: print("hello", end="") or x*2)("hi"))3^2
x = 5 print([y//2 for y in range(6)][x])
d = {1: 'first', 2: 'second'}
d[4] = None
print(len(d))a = [1, 5, 7] b = [2, 4, 6] c = a.extend(b) print(c)