Python Tasks & ML | Задачи по питону и машинному обучению
9.39K subscribers
27 photos
1 file
36 links
Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn
https://telega.in/c/python_tasks

Questions — @dina_ladnyuk
Download Telegram
Что выведет код?
x = 5
print([y%2 for y in range(6)][x])
👍2
Что выведет код?
def func(x):
if x >= 3:
return x
y = filter(func, (1, 2, 3, 4))
print(list(y))
Что выведет код?
def f(x):
if x < 3:
return x
y = filter(f, (0, 1, 2, 3, 4))
print(list(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)
👍2
Что выведет код?
from functools import reduce
y = reduce(lambda a, b: a + b , [1, 2, 3, 4])
print(y)
Что выведет код?
x = {1: "A", 3: "B"}
y = {2: "C", 3: "D", 4: "E"}
d = {**x, **y}
vals = sorted(d.values())
print(*vals)
🔥4
Что выведет код?
c = map(lambda x: x + x, filter(lambda x: (x>3), (1, 2, 3, 4)))
print(list(c))
👍3
Что выведет код?
c = filter(lambda x: x>=3, map(lambda x: x+x, (1, 2, 3, 4)))
print(list(c))
Что выведет код?
def unpacking(x, y):
print(x, y, end=" ")
tuple_vec = (1, 0)
dict_vec = {'x': 1, 'y': 0}
unpacking(*tuple_vec)
unpacking(**dict_vec)
👍1
Что выведет код?
x = 1
def f():
def g():
nonlocal x
print(x)
x += 1
return g