ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(list(range(-3, 3)), list(zip(range(3), 'ab')))
- A. [-3, -2, -1, 0, 1, 2] [(0, 'a'), (1, 'b'), (2, None)]
- B. [-3, -2, -1, 0, 1, 2] [(0, 'a'), (1, 'b')]
- C. [-3, -2, -1, 0, 1, 2, 3] [(0, 'a'), (1, 'b')]
- D. [-2, -1, 0, 1, 2] [(0, 'a'), (1, 'b')]
Correct answer: B. [-3, -2, -1, 0, 1, 2] [(0, 'a'), (1, 'b')]
range(-3, 3) stops before 3. zip stops at the shorter input, which is the two-letter string.
More Python Programming questions
- Why is del a[0] on a Python list O(n), while a.pop() is O(1)?
- For a sliding-window maximum over an array of n = 2 10^5 values, which Python structure gives an O(n) total algorithm?
- What is the usual fastest way to read n = 10^6 integers from one input line in Python for a judge?
- What is printed? python import heapq print(heapq.nsmallest(2, [5, 1, 4, 1]), list(reversed(range(3))), list(reversed('ab')))
- What is printed? python print(any(map(str.isdigit, 'ab1')), all(map(str.isalpha, 'ab1')))
- What is printed? python print(sorted({'b': 1, 'a': 2}.items()), sum([1, 2, 3], start=10))