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]]
Choose the correct answer
Anonymous Quiz
38%
True
25%
False
17%
TypeError
13%
SyntaxError
8%
See solution
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
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)
❤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:])
Choose the correct answer
Anonymous Quiz
8%
100 d99
4%
100 889
40%
100 899
0%
200 d99
8%
200 889
0%
200 899
16%
1024 d99
4%
1024 889
8%
1024 899
12%
See solution
👍1
What will this code do?
from functools import partial
from operator import gt
gt = partial(gt, 0)
l = list(filter(gt, [x for x in range(-2, 3) if x >= 0]))
print(l)
Choose the correct answer
Anonymous Quiz
11%
[]
3%
[-2, -1]
20%
[1, 2]
17%
[-2, -1, 0]
14%
[0, 1, 2]
17%
[-2, -1, 1, 2]
6%
[0]
11%
See solution
What will this code do?
M = [[1, 2], [3, 4]]
N = [[5, 6], [7, 8]]
sum([col1*col2 for row1, row2 in zip(M, N) for col1, col2 in zip(row1, row2)])
Choose the correct answer
Anonymous Quiz
10%
36
12%
62
24%
70
27%
94
15%
100
5%
5760
7%
See solution
Which of the functions must be explicitly imported in order to use it?
Anonymous Quiz
17%
map
10%
filter
13%
reduce
10%
vars
23%
classmethod
6%
dir
6%
repr
15%
See solution
Are given 4 code variant:
#1
[х ** 2 for х in range(5) if х % 2 == 0]
#2
list(map(lambda x: x**2, filter(lambda x: x % 2 == 0, range(5))))
#3
res = []
for x in range(5):
if x % 2 == 0:
y = x**2
res.append(y)
print(res)
#4
list(map(lambda x: x ** 2 % 4 == 0, range(5)))
❤1
Which of the options will not bring [0, 4, 16]?
Anonymous Quiz
9%
1
19%
2
32%
3
32%
4
9%
See solution
What will this code do?
[((x // y):) for х in range(3) if х % 2 == 0 for y in range(3) if y % 2 == 1]