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?
import re
sent = 'Hello, Ben! How are you doing?'
lister = filter(None, re.split("[,!?]+", sent))
print(len(list(lister)))
👍1🤯1
Given code
def f(n):
def g(x):
return x ** n
return g

g = f(3)
print(g(2), g(3))
What will this code do?
from itertools import product
a = [1, 2]
b = [3, 4]
sum(sum(product(a, b), (0, 0)))
👍1🤯1
What will this code do?
def f(x):
try:
print('1', end=" ")
y = 1 * 0 if x % 2 else 1 / 0
except:
y = 0
print('2', end=" ")
else:
print('3', end=" ")
finally:
print('4', end=" ")
return y

print(f(1) + f(2))
What will this code do?
class A:
def __init__(self, x=0):
self.x = x
def f(self):
print(self.x)
a = A(2020)
f = a.f
print(f.__self__ is a, end=" ")
print(f.__func__ is f, end=" ")
print(f.__func__ is a.f, end=" ")
print(f.__func__ is A.f, end=" ")
👍1
What will this code do?
import numpy as np
print(np.asarray([100, 200, 300]).astype(np.int8))
What will this code do?
import numpy as np
print(np.uint8(1 - 2))
What will this code do?
import numpy as np
mat = np.array([[1, 2], [4, 5]])
print(round((mat @ np.linalg.inv(mat)).sum()))
Choose the right option for "callables"
class A:
def __init__(self, x):
self.x = x
def __call__(self):
return self.x
class B:
def __init__(self, x):
self.x = x
def method(self):
return self.x
class C:
def __init__(self, x=3):
self.x = x
def __repr__(self):
return str(self.x)
a = A(1)
b = B(2)
c = C(3)
callables = # your code
print([act() for act in callables])
#Output [1, 2, 3]