Python Tasks & ML | Задачи по питону и машинному обучению
9.4K 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
Что выведет код?
from collections import namedtuple
Uni = namedtuple('Uni', ['num_student', 'num_groups'])
a = [(10, 4), (5, 3), (9, 5)]
def f(records):
res = 0.0
for r in records:
s = Uni(*r)
res += s.num_student * s.num_groups
return res
print(f(a))
👍1
Дан код:
from collections import namedtuple
A = namedtuple('A', ['x', 'y', 'z'])
a = A(1, 2, 3)
d = dict(x=1, y=2, z=3)
sa = a.__sizeof__()
sd = d.__sizeof__()
Что выведет код?
from collections import namedtuple
A = namedtuple('A', ['x', 'y'])
a = A('A', ['1', '2'])
a.x = 3
print(a.x)
Что выведет код?
from collections import namedtuple
A = namedtuple('A', ['x', 'y'])
a = A('A', ['1', '2'])
a = a._replace(x=3)
print(a.x)
Что выведет код?
from collections import namedtuple
A = namedtuple('A', ['x', 'y'])
a = A(0, 0)
d = {'x': 1, 'y': 2}
a = a._replace(**d)
print(a.x + a.y)
Выберите предпочтительный (в смысле потребления ресурсов) метод нахождения суммы числе от 1 до 10**9:
Anonymous Quiz
13%
sum({x for x in range(10**9)})
18%
sum([x for x in range(10**9)])
47%
sum(x for x in range(10**9))
9%
Все одинаковы
13%
Посмотреть результаты
Что выведет код?
from operator import itemgetter
ds = [{"x": 1}, {"x": 2, "y": 3}]
min1 = min(ds, key=itemgetter('x'))
min2 = min(i['x'] for i in ds)
print(min1 == min2)
Что выведет код?
from collections import ChainMap
a = {'x': 1, 'z': 3 }
b = {'y': 2, 'z': 4 }
c = ChainMap(a,b)
print(c['x'] + c['y'] - c['z'])
Что выведет код?
from collections import ChainMap
d1 = {'x': 1, 'z': 10}
d2 = {'y': 2, 'z': 20}
d3 = {**d1, **d2}
d4 = ChainMap(d1, d2)
s1 = d3['x'] + d3['y'] + d3['z']
s2 = d4['x'] + d4['y'] + d4['z']
print(s1, s2)
Что выведет код?
from collections import ChainMap
a = {'x': 1, 'z': 3 }
b = {'y': 2, 'z': 4 }
c = ChainMap(a,b)
c['z'] = 10
c['w'] = 40
del c['x']
print(sum(a.values()), sum(b.values()))
Что выведет код?
from collections import ChainMap
a = {'x': 1}
b = {'x': 2}
c = {'x': 3}
d = ChainMap(a, b, c)
del d['x']
del d['x']
print(d['x'])