ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(min(map(str, [10, 9, 100])), sorted(['10', '9', '100']), sorted([10, 9, 100]))
- A. 9 ['10', '100', '9'] [9, 10, 100]
- B. 10 ['9', '10', '100'] [9, 10, 100]
- C. 10 ['10', '100', '9'] [10, 9, 100]
- D. 10 ['10', '100', '9'] [9, 10, 100]
Correct answer: D. 10 ['10', '100', '9'] [9, 10, 100]
Strings compare character by character, so '10' is the smallest of the strings. Sorting the numbers in strings gives '10', '100', '9', and sorting ints gives 9, 10, 100.
More Python Programming questions
- What is printed? python print(len([x for x in range(10) if x % 3 == 0]), sum(range(0, 10, 3)))
- What is printed? python x = [3, 1, 2] y = sorted(x) x.sort(reverse=True) print(x, y, x is y)
- 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))