ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(sorted([[2, 'b'], [1, 'z'], [2, 'a']]))
- A. [[2, 'a'], [1, 'z'], [2, 'b']]
- B. [[1, 'z'], [2, 'a'], [2, 'b']]
- C. [[1, 'z'], [2, 'b'], [2, 'a']]
- D. [[2, 'b'], [2, 'a'], [1, 'z']]
Correct answer: B. [[1, 'z'], [2, 'a'], [2, 'b']]
Lists compare element by element, so the smallest first item is 1. Among the two items starting with 2, the letters decide the order.
More Python Programming questions
- What is printed? python x = [1, 2, 3] y = x.copy() y.append(4) print(len(x), len(y), x is y)
- What is printed? python print('aaa' < 'b', 'abc' > 'abd')
- What is printed? python print(sum(1 for c in 'hello world' if c in 'aeiou'))
- What is printed? python print(list(filter(lambda x: x > 0, map(lambda x: x - 2, [1, 2, 3, 4]))))
- What is printed? python print(1e3, 1000.0 == 1e3, 10 -2)
- What is printed? python print(type(True + 1).name, type(2 1.0).name)