ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
m = [[1, 2, 3], [4, 5, 6]] rot = [list(r) for r in zip(*m[::-1])] print(rot)
- A. [[1, 4], [2, 5], [3, 6]]
- B. [[4, 1], [5, 2], [6, 3]]
- C. [[6, 3], [5, 2], [4, 1]]
- D. [[3, 6], [2, 5], [1, 4]]
Correct answer: B. [[4, 1], [5, 2], [6, 3]]
Reversing the rows and then transposing with zip rotates the matrix 90 degrees clockwise. The first new row is the first column read from bottom to top.
More Python Programming questions
- What is printed? python def hist(h): st = [] best = 0 h = h + [0] for i, x in enumerate(h): start = i while st and st[-1][1] >= x: idx…
- What is printed? python def knap(items, cap): dp = [0] (cap + 1) for w, v in items: for c in range(cap, w - 1, -1): dp[c] = max(dp[c]…
- What is printed? python from collections import deque def knight(src, dst): seen = {src: 0} q = deque([src]) moves = [(1, 2), (2, 1), (-1…
- For an array of n = 10^5 values, which approach counts the distinct values in every window of size k = n / 2 in the least total time?
- What is printed? python a = [1, 2, 3, 4] try: print(a[len(a) / 2]) except TypeError: print('TypeError') print(a[len(a) // 2])
- What is printed? python s = 'u00b2' print(s.isdigit(), s.isdecimal(), s.isnumeric())