TGViewer
Channel Public Channel
Python Tasks & ML | Задачи по питону и машинному обучению

Python Tasks & ML | Задачи по питону и машинному обучению

@python_tasks

Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn
https://telega.in/c/python_tasks

Questions — @dina_ladnyuk
Subscribers
8.52K
Photos
30
Videos
1
Links
41

Showing posts older than #2982 · Back to latest

Older Posts 20 shown
Post #2981 639
Что выведет код?

def gen():
yield 1
return 2

g = gen()
print(next(g))
print(next(g))
  • 👨‍💻 1
Post #2979 629
Что выведет код?

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)
Post #2977 694
Что выведет код?

from itertools import groupby

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

print(groups)
Post #2975 693
Что выведет код?

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))
Post #2973 639
Что выведет код?

from itertools import tee

it = iter([10, 20, 30])
a, b = tee(it)

print(next(a), next(b), list(a), list(b))
Post #2971 661
Что выведет код?

def flatten(lst):
for item in lst:
if isinstance(item, list):
yield from flatten(item)
else:
yield item

print(list(flatten([1, [2, [3, 4]], 5])))
Post #2969 665
Что выведет код?

 echo():
value = yield "start"
yield value

g = echo()
print(next(g))
print(g.send("hello"))
Post #2967 697
Что выведет код?

from contextlib import contextmanager

@contextmanager
def simple_context():
print("enter")
yield
print("exit")

with simple_context():
print("inside")
Post #2965 651
Что выведет код?

g = (x for x in range(2))
print(next(g), next(g), next(g, 99))
Post #2963 646
Что выведет код?

def sub():
for i in range(2):
yield i

def main():
yield -1
for x in sub():
yield x
yield 2

print(list(main()))
Older posts →
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →