Python Tasks & ML | ΠΠ°Π΄Π°ΡΠΈ ΠΏΠΎ ΠΏΠΈΡΠΎΠ½Ρ ΠΈ ΠΌΠ°ΡΠΈΠ½Π½ΠΎΠΌΡ ΠΎΠ±ΡΡΠ΅Π½ΠΈΡ
Kanalga Telegramβda oβtish
Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn https://telega.in/c/python_tasks Questions β @dina_ladnyuk
Ko'proq ko'rsatish8 557
Obunachilar
Ma'lumot yo'q24 soatlar
-37 kunlar
-3430 kunlar
Postlar arxiv
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
def f(*args):
result = []
for x in args[0]:
for word in args[1:]:
if x not in word:
break
else:
result.append(x)
return ''.join(result)
s1, s2, s3= "message", "massage", "mask"
print(f(s1, s2, s3))ΠΠ°ΠΊΠΎΠΉ ΡΠΏΠΎΡΠΎΠ± ΠΏΡΠΎΠ²Π΅ΡΠΊΠΈ ΡΠΎΠ³ΠΎ, ΡΡΠΎ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½Π°Ρ a ΡΠ²ΡΠ·Π°Π½Π° Ρ None, ΡΠ²Π»ΡΠ΅ΡΡΡ Π±ΠΎΠ»Π΅Π΅ ΠΏΡΠ΅Π΄ΠΏΠΎΡΡΠΈΡΠ΅Π»ΡΠ½ΡΠΌ?
ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
def f(*args):
result = []
for x in args[0]:
if x in result:
continue
for word in args[1:]:
if x not in word:
break
else:
result.append(x)
return ''.join(result)
s1, s2, s3= "message", "massage", "mask"
print(f(s1, s2, s3))ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
def mintwo(*args):
tmp = list(args)
tmp.sort()
return tmp[0], tmp[1]
data = [8, -4, 5, -2, 9, 3, -98]
print(*mintwo(*data))ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
def f(transform, *args):
res = args[0]
for arg in args[1:]:
res = transform(res, arg)
return res
data = [-4, 2, -1, 5, -6, 3]
func = lambda x, n: x * (-1)**n
print(int(f(func, *data)))ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
def f(test, *args):
res = []
for arg in args:
if test(arg):
res.append(arg)
return sum(res)
data = [-4, 2, -1, 5, -6, 3]
negative = lambda x: x < 0
neg = f(negative, *data)
positive = lambda x: x > 0
pos = f(positive, *data)
print(neg, pos)ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
def maker(f, args, kwargs):
return 1 + f(*args, **kwargs)
m1 = maker(lambda a, b: a + b, (5, ), {"b": 2})
m2 = maker(lambda a, b: a * b, [4, 5], {})
print(m1 + m2)ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
def f(s:str = "1") -> int:
return s * 2
print(f(), isinstance(f(), int))ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
def f(a, b, c, d, e):
print(a, b, c, d, e)
f(1, *(3,), c=10, **{"d": 5, "e": 100})ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ
Π§ΡΠΎ Π²ΡΠ²Π΅Π΄Π΅Ρ ΠΊΠΎΠ΄?
x = 1
def f():
def g():
nonlocal x
print(x)
x += 1
return gΠΠ°ΠΊΠΎΠ΅ ΠΎΠ±ΡΡΠ²Π»Π΅Π½ΠΈΠ΅ ΡΡΠ½ΠΊΡΠΈΠΈ Π½Π΅ Π²ΡΠ·ΠΎΠ²Π΅Ρ ΠΎΡΠΈΠ±ΠΊΡ Π²ΠΎ Π²ΡΠ΅ΠΌΡ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ ΡΡΠ½ΠΊΡΠΈΠΈ?
ΠΠ°ΠΊΠΎΠΉ ΡΠΏΠΎΡΠΎΠ± ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠΈ Π°ΡΠ³ΡΠΌΠ΅Π½ΡΠΎΠ² ΠΏΡΠΈ Π²ΡΠ·ΠΎΠ²Π΅ ΡΡΠ½ΠΊΡΠΈΠΈ Π²ΡΠ·ΠΎΠ²Π΅Ρ ΠΎΡΠΈΠ±ΠΊΡ?
