ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = [3, 1, 2] y = sorted(x) x.sort(reverse=True) print(x, y, x is y)
- A. [3, 2, 1] [1, 2, 3] True
- B. [3, 2, 1] [1, 2, 3] False
- C. [1, 2, 3] [1, 2, 3] False
- D. [3, 2, 1] [3, 2, 1] True
Correct answer: B. [3, 2, 1] [1, 2, 3] False
sort(reverse=True) reorders x in place. sorted made y a separate list before that, so it keeps the ascending order.
More Python Programming questions
- What is printed? python print(list(map(sum, zip([1, 2], [3, 4]))), list(zip([[1, 2], [3, 4]])))
- What is printed? python print(10 // 3 3 + 10 % 3 == 10, -10 // 3 3 + -10 % 3 == -10, 10 // -3 -3 + 10 % -3 == 10)
- What is printed? python print(0 == False, '' == False, [] == False, None == False)
- What is printed? python from collections import Counter print(Counter('hello').mostcommon(2))
- What is printed? python def keyfn(p): return (-p[1], p[0]) people = [('bo', 3), ('al', 5), ('cy', 3)] print([p[0] for p in sorted(people…
- What is printed? python s = 'abcabc' print(s.find('c'), s.find('c', 3), s.rfind('c', 0, 4), s.count('c', 2))