Python & ML tasks
415 subscribers
2 photos
3 links
Python, functions, classes, iterators, generators, numpy, pandas, scikit-learn, TensorFlow
for advertising: @dina_ladnyuk

For advertising and donations in USD:
SWIFTBIC BUKBGB22
IBAN GB40 BUKB 2047 3453 2396 99
Mrs Dina Ladnyuk
Download Telegram
What will this code do?
def f(n):
s = 0
for i in range(n):
s += i
s += ~i
return s
print(f(1) + f(10) + f(100))
🤩1
What will this code do?
-453492 % 101 + 453492 % 101
👍2
Which of the classes from the scikit-learn library does NOT solve the problem of regression?
Anonymous Quiz
17%
DecisionTreeRegressor
20%
RandomForestRegressor
20%
LinearRegression
37%
LogisticRegression
7%
See solution
👍1
What will this code do?
class MyList(list):
def __getitem__(self, index):
if type(index) is slice:
index = slice(index.start - 1, index.stop - 1, index.step)
elif type(index) is int:
index -= 1
return list.__getitem__(self, index)

l = MyList(["one", "two", "three", "four", "five", "six"])

print(l[1], l[-1], l[0], l[2:4])
What will this code do?
a = 1 * 1
b = 1 / 1
print(a == 1, b == 1, a is 1, b is 1)
What will this code do?
class A:
def __init__(self, x):
self.x = x
def __getattribute__(self, name):
if name == '__add__':
self.x *= 10
return object.__getattribute__(self, name)
def __add__(self, other):
return self.x + other.x

a1 = A(2)
a2 = A(3)
print(a1 + a2, a1.__add__(a2))
👍1
What will this code do?
S = 'abcdef'
print(S.islower() + S.lower().isalpha() + S.isupper())
What will this code do?
class A:
def __getitem__(self, i):
return i
a = A()
a.__getitem__ = lambda i: i**2

print(a[4])
What will this code do?
from functools import reduce
print(reduce(lambda acc, x: x * acc, [1,2,3,4], 1))
👍1
What will this code do?
class A:
x = 'hello'
def __getitem__(self, i):
return getattr(self.x, '__getitem__')(i) * 2
def __getattr__(self, attr):
return getattr(self.x, attr)
a = A()
print(a[0] + a.upper()[1:])