ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
print(sorted([('b', 2), ('a', 2), ('c', 3)], key=lambda t: (-t[1], t[0])))- A. [('b', 2), ('a', 2), ('c', 3)]
- B. [('c', 3), ('b', 2), ('a', 2)]
- C. [('a', 2), ('b', 2), ('c', 3)]
- D. [('c', 3), ('a', 2), ('b', 2)]
Correct answer: D. [('c', 3), ('a', 2), ('b', 2)]
Negating the count sorts higher counts first, and the name breaks ties alphabetically. So c with 3 comes first, then a and b.
More Python Programming questions
- What is printed? python def ok(s): def chk(l, r): while l < r: if s[l] != s[r]: return False l += 1 r -= 1 return True l, r = 0, len(s)…
- What is printed? python def removek(num, k): st = [] for d in num: while k and st and st[-1] > d: st.pop() k -= 1 st.append(d) st =…
- What is printed? python def divcount(a, k): cnt = {0: 1} s = 0 ans = 0 for x in a: s = (s + x) % k ans += cnt.get(s, 0) cnt[s] =…
- What is printed? python print(sorted(['b', 'A', 'a', 'B']), sorted(['b', 'A', 'a', 'B'], key=str.lower))
- What is printed? python print('a-b-c-d'.rsplit('-', 2), 'a-b-c-d'.split('-', 1))
- What is printed? python print('²'.isdigit(), '²'.isdecimal(), '٣'.isdecimal())