ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
a = [3, 1, 2] b = sorted(a, reverse=True)[:2] c = sorted(a)[-2:] print(b, c, sum(b) + sum(c))
- A. [3, 2] [2, 3] 10
- B. [3, 1] [1, 2] 7
- C. [3, 2] [1, 2] 8
- D. [3, 2] [2, 3] 11
Correct answer: A. [3, 2] [2, 3] 10
b is the two largest values in descending order, [3, 2]. c is the two largest values in ascending order, [2, 3]. Their sums are 5 and 5, which total 10.
More Python Programming questions
- What is printed? python word = 'Level' print(word.lower() == word.lower()[::-1], word == word[::-1], word.casefold() == 'level')
- What is printed? python d = {} for w in ['b', 'a', 'b']: d[w] = d.get(w, 0) + 1 print(d, max(d, key=d.get), sorted(d.values()…
- Which is the time complexity of checking whether a string s of length n is a palindrome, using s == s[::-1]?
- What is printed? python values = [0, 1, 2, 3] print([v for v in values if v] == values[1:], any(values), all(values[1:]))
- What is printed? python import heapq nums = [7, 2, 9] heapq.heapify(nums) print(nums[0], heapq.nlargest(1, nums)[0], heapq.nsmallest(2…
- What is printed? python print(any(x > 3 for x in range(10)), next(x for x in range(10) if x x > 20), sum(x for x in range(0, 10, 4)))