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
What will this code do?
def f(a: int = 7) -> int:
return 2 + int(a)
print(f(3.5))
What will this code do?
list(map(pow, [1, 2, 3], [2, 3, 4]))
What will this code do?
def f(x: 1 = 1):
f.__annotations__["x"] += x
return f.__annotations__["x"]
print(f(), f(), f(10))
The function is given
def f(x: int = 1):
if type(x) is not f.__annotations__["x"]:
raise TypeError("Incorrect argument type x!")
f.__annotations__["x"] = float
return x**2
What will this code do?
def f(x): 
return x + 2
list(map(f, [1, 2, 3, 4])) == [f(x) for x in [1, 2, 3, 4]]
Are given 4 code variant:
# 1 Option
list(filter((lambda x: x > 0) , range(-5, 5)))
# 2 Option
res = []
for x in range(-5, 5):
if x > 0:
res.append(x)
print(res)
# 3 option
[x for х in range(-5, 5) if х > 0]
# 4 Option
list(map(lambda x: x > 0, range(-10, 5)))
Which of the options will not display the numbers 1, 2, 3, 4?
Anonymous Quiz
14%
1 Option
5%
2 Option
27%
3 Option
41%
4 Option
14%
See solution
What functional programming function does?
def f(function, sequence):
s = sequence[0]
for x in sequence[1:]:
s = function(s, x)
return s
Choose the correct answer
Anonymous Quiz
31%
map
27%
filter
31%
reduce
12%
lambda
0%
See solution
What will this code do?
import operator, functools
x1 = functools.reduce(operator.add, [2, 4, 6])
x2 = functools.reduce((lambda x, y: x + y) , [2, 4, 6])
print(x1 == x2)
Choose the correct answer
Anonymous Quiz
42%
True
19%
False
27%
SyntaxError
12%
See solution
1
What will this code do?
def f(acc, x):
acc[x] = x * 2
return acc
reduce(f, ["a", 3, (1,2)], {})
What will this code do?
password = 'password'
adding = [х + y for х in '0123456789' for y in '0123456789']
count = 0
for a in adding:
password = password + a
count += 1
print(count, password[-3:])