ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(list(zip('ab', 'cd', 'ef'))[1], dict(zip('ab', [1])))- A. ('b', 'd', 'f') {'a': 1, 'b': 1}
- B. ('b', 'd', 'f') {'a': 1, 'b': 0}
- C. ('b', 'd', 'f') {'a': 1}
- D. ('b', 'd') {'a': 1, 'b': None}
Correct answer: C. ('b', 'd', 'f') {'a': 1}
All three strings have length 2, so the second tuple holds b, d and f. dict of zip stops at the shorter input, so only 'a' gets the value 1.
More Python Programming questions
- What is printed? python print(len('héllo'), len('héllo'.encode('utf-8')), 'é'.encode('utf-8'))
- What is printed? python import math print(math.floor(7 / 2) 2 + 7 % 2, 7 // 2 2 + 7 % 2)
- What is printed? python x = [0] 3 x[0] += 1 x = x 2 x[3] += 5 print(x)
- What is printed? python from collections import Counter c = Counter('aab') c.subtract('ab') print(c['a'], c['b'], sorted((+c).items()))
- What is printed? python n = 100 z, p = 0, 5 while p <= n: z += n // p p = 5 print(z, len(str(import('math').factorial(n)))…
- What is printed? python n, steps = 27, 0 while n != 1: n = n // 2 if n % 2 == 0 else 3 n + 1 steps += 1 print(steps, n)