ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from collections import deque d = deque(range(5)) d.rotate(-2) print(list(d), d[0], d[-1])
- A. [0, 1, 2, 3, 4] 2 1
- B. [2, 3, 4, 0, 1] 2 1
- C. [3, 4, 0, 1, 2] 3 2
- D. [2, 3, 4, 0, 1] 0 4
Correct answer: B. [2, 3, 4, 0, 1] 2 1
rotate(-2) moves the first two items to the end, giving 2, 3, 4, 0, 1. The first and last items are then 2 and 1.
More Python Programming questions
- What is printed? python import heapq h = [] for x in [5, 1, 3]: heapq.heappush(h, x) heapq.heappush(h, 0) print([heapq.heappop(h) for in…
- What is printed? python s = 'hello' print(s.index('l'), s.rfind('l'), s.find('l', 3), s.index('lo'))
- What is printed? python import itertools print(sum(1 for in itertools.combinations(range(6), 2)), sum(1 for in…
- Which of the following statements about Python's sort is correct for CP problems?
- What is printed? python def solve(n): if n == 0: return [] return solve(n // 2) + [n % 2] print(solve(6), solve(0))
- What is printed? python print(divmod(7, -3), 7 % -3, -7 % 3, -7 // 3)