What will this code do?
def f(transform, *args):
res = args[0]
for arg in args[1:]:
res = transform(res, arg)
return res
data = [-4, 2, -1, 5, -6, 3]
func = lambda x, n: x * (-1)**n
print(f(func, *data))
Choose the correct answer
Anonymous Quiz
0%
-720
33%
-4
11%
-1
11%
1
33%
4
11%
[4, -2, 1, -5, 6, -3]
0%
See solution
What will this code do?
def mintwo(*args):
tmp = list(args)
tmp.sort()
return tmp[0], tmp[1]
data = [8, -4, 5, -2, 9, 3, -98]
print(*mintwo(*data))
Choose the correct answer
Anonymous Quiz
7%
-102
0%
-98
7%
-2
14%
8 -4
64%
-98 -4
0%
9 8
0%
(8, -4)
7%
(-98, -4)
0%
(9, 8)
0%
See solution
What will this code do?
def f(*args):
result = []
for x in args[0]:
if x in result:
continue
for word in args[1:]:
if x not in word:
break
else:
result.append(x)
return ''.join(result)
s1, s2, s3= "message", "massage", "mask"
print(f(s1, s2, s3))
Choose the correct answer
Anonymous Quiz
20%
mesagk
20%
mssa
30%
msa
10%
mesag
0%
message
0%
massage
0%
mask
0%
messagemassagemask
10%
blank line
10%
See solution
What is the way to verify that the variable `a` in connection with none, is it preferable?
Anonymous Quiz
15%
if not a:
31%
if a == None:
38%
if a is None:
15%
if bool(a) == False:
0%
if bool(a) is False:
What will this code do?
def f(*args):
result = []
for x in args[0]:
for word in args[1:]:
if x not in word:
break
else:
result.append(x)
return ''.join(result)
s1, s2, s3= "message", "massage", "mask"
print(f(s1, s2, s3))
Choose the correct answer
Anonymous Quiz
0%
mesagk
38%
mssa
15%
msa
0%
mesag
15%
message
0%
massage
0%
mask
8%
messagemassagemask
23%
blank line
0%
See solution
What will this code do?
def f(*args):
res = ""
l = len("".join(args[:-1]))
for i, s in enumerate("".join(args)):
if i > l:
res += s
return res
s1, s2, s3= "one", "two", "three"
print(f(s1, s2, s3))
Choose the correct answer
Anonymous Quiz
50%
three
25%
hree
8%
two
0%
wo
8%
one
0%
ne
8%
onetwothree
0%
newohree
0%
Check my result of "{0}"
What will this code do?
def mineven(*args):
res = args[0]
for arg in args[1: ]:
if arg < res and arg % 2 == 0:
res = arg
return res
data = [3, 2, 1, 0, -1, -2, -3]
mineven(*data)
Choose the correct answer
Anonymous Quiz
0%
-3
67%
-2
8%
-1
17%
0
8%
[2, 0, -2]
0%
[-1, -2, -3]
0%
[-3, -2, -1, 0, 1, 2]
0%
See solution
What will this code do?
def f(*args):
result = []
for seq in args:
for x in seq:
if not x in result:
result.append(x)
return ''.join(result)
s1, s2, s3= "message", "massage", "mask"
print(f(s1, s2, s3))
Choose the correct answer
Anonymous Quiz
50%
mesagk
0%
mssa
0%
msa
8%
mesag
8%
message
0%
massage
0%
mask
25%
messagemassagemask
8%
blank line
0%
Check my result of "{0}"
What will this code do?
def f(*args):
result = []
for x in args[0]:
for w in args[1:]:
if x in w:
break
else:
result.append(x)
return "".join(result)
s1, s2, s3= "hello", "hi", "good morning"
print(f(s1, s2, s3))
Choose the correct answer
Anonymous Quiz
10%
hellohigoodmorning
20%
hello
10%
good morning
10%
hi
50%
ell
0%
heloigd mrn
0%
blank line
0%
See solution
What will this code do?
sorted([1, 2, 3, 4, 5], key=lambda x: -x, reverse=True)
Choose the correct answer
Anonymous Quiz
33%
[1, 2, 3, 4, 5]
6%
[-1, -2, -3, -4, -5]
6%
[5, 4, 3, 2, 1]
39%
[-5, -4, -3, -2, -1]
6%
None
6%
TypeError
6%
See solution
What will this code do?
def f(arr):
if not arr:
return 0
return arr[0] + f(arr[1:])
f([1, 2, 3, 4, 5])