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
Что выведет код?
class X:
def __init__(self, l):
self.l = l
def __iter__(self):
return (x for x in self.l)
a = X([1, 2])
b = X([3, 4])
print(*chain(a, a, b, b))
Что выведет код?
class X:
def __init__(self, l):
self.it = (x for x in l)
def __iter__(self):
return self.it
a = X([1, 2])
b = X([3, 4])
print(*chain(a, a, b, b))
Что выведет код?
from collections import Iterable
items = [1, [2, 3, [4], 5], 6]
def flatten(items):
for x in items:
if isinstance(x, Iterable):
yield from flatten(x)
else:
yield x

print(*flatten(items))
Что выведет код?
import heapq
a = [1, 4]
b = [2, 5]
for c in heapq.merge(a, b):
print(c, end='')
Что выведет код?
from itertools import repeat, chain
x = [1, 2]
print(*chain(*repeat(x, 2)))
Что выведет код?
import numpy as np
a = np.array([1, 2, np.nan, np.nan])
print(np.min(a), np.nanmin(a))
Что выведет код?
import numpy as np
a = np.array([1, 2, np.nan, np.nan])
print(np.max(a), np.nanmax(a))
Что выведет код?
import numpy as np
x = np.fmin([1, -5, 6], [0, np.nan, -1])
print(*x)
👍2
Что выведет код?
import numpy as np
x = np.fmax([1, -5, 6], [2, np.nan, -1])
print(*x)