Python & ML tasks
416 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
๐Ÿ‘1
What will this code do?
class A: attr = 1  
class B(A): pass
class ะก(A): attr = 2
class D(B, ะก): pass
x = D()
print(x.attr)
๐Ÿ‘1
๐Ÿ‘1
What will this code do?
a = type([1, 2, 3]) == type(list)
b = [1, 2, 3].__class__ == list.__class__
print(a, b)
๐Ÿ‘1
What will this code do?
class A: attr = 1  
class B(A): pass
class C(B): pass
class D(A): attr = 2
class E(C, D): attr = C.attr
x = E()
print(x.attr)
๐Ÿ‘1
๐Ÿ‘1
What will this code do?
int(2) is 2 * True
๐Ÿ‘1
๐Ÿ‘1
What will this code do?
class A: pass
class B(A): pass
class C1(A): pass
class C2: pass
class D1(B, C1): pass
class D2(B, C2): pass

X = list(D1.__mro__)
Y = list(D2.__mro__)
print(X[3] is Y[2])
๐Ÿ‘1
๐Ÿ‘1
What will this code do?
class MyList(list):
def __getitem__(self, index):
return super().__getitem__(index) * 2
m = MyList([1, 2])
print([m[i] + x for i, x in enumerate(m)])
๐Ÿ‘1
What will this code do?
def invertdict(D):
def keysof(V):
return sorted(K for K in D.keys() if D[K] == V)
return {V: keysof(V) for V in set(D.values())}
D = {'x': 'a', 'y': 'b', 'z': 'a'}
print(invertdict(D))
What will this code do?
s = "Hello, world!"
s.find("world", 0, 7) + s.find("world", 5)
๐Ÿคฏ2๐Ÿ”ฅ1
What will this code do?
class D:
__slots__ = ['a', 'b']
d = D()
d.a = 1
f = lambda attr: getattr(d, attr, '*')
print(f('a'), f('b'), f('__dict__'))
๐Ÿ‘1
๐Ÿ‘1
What will this code do?
import numpy as np
a = np.array([1, 2, 3])
n1 = round(np.linalg.norm(a, ord=np.inf), 1)
n2 = round(np.linalg.norm(a, ord=1), 1)
n3 = round(np.linalg.norm(a, ord=2), 1)
print(n1, n2, n3)
๐Ÿ‘1