Python Tasks & ML | Задачи по питону и машинному обучению
9.32K 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
Что выведет код?

with open("data.txt", "w", encoding="utf-8") as f:
f.write("apple\n")
f.write("banana\n")
f.write("cherry\n")

def read_lines():
for line in open("data.txt"):
yield line.strip()

lines = read_lines()
print(next(lines))
print(next(lines))
print(next(lines))
Что выведет код?

from itertools import groupby

data = ['a', 'a', 'b', 'b', 'b', 'a']
groups = [(k, list(g)) for k, g in groupby(data)]

print(groups)
Что выведет код?

from itertools import groupby

words = ["apple", "apricot", "banana", "blueberry"]
groups = [(k, list(g)) for k, g in groupby(words, key=lambda x: x[0])]

print(groups)
Что выведет код?

def gen():
yield 1
return 2

g = gen()
print(next(g))
print(next(g))
Что выведет код?

def sub():
value = yield
yield f"got: {value}"

def main():
yield from sub()

g = main()
next(g)
print(g.send("hello"))
Что выведет код?

nums = [1, 2, 3]
result = list(map(lambda x: x * 2, nums))
print(result)
Что выведет код?

nums = [0, 1, 2, 3, 4]
evens = list(filter(lambda x: x % 2 == 0, nums))
print(evens)