ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print('a,,b,'.split(','), ' a b '.split(' '))- A. ['a', '', 'b', ''] ['a', 'b', 'x']
- B. ['a', '', 'b', ''] ['', 'a', '', 'b', '']
- C. ['a', 'b'] ['a', 'c']
- D. ['a', '', 'b'] ['', 'a', 'd', '']
Correct answer: B. ['a', '', 'b', ''] ['', 'a', '', 'b', '']
split(',') keeps empty fields, so the trailing comma leaves an empty last item. split(' ') with an explicit space keeps the empty fields between the double space and at both ends, unlike split() with no argument.
More Python Programming questions
- What is printed? python print('1.2.3.4'.rsplit('.', 1), 'x'.partition('='), 'a=b=c'.partition('='))
- What is printed? python print(chr(ord('a') + 27), ord('Z') - ord('A'), chr(0x1F600) == 'U0001F600', len('U0001F600'))
- Which of the following Python operations on a built-in container is O(1) on average (independent of the container size)?
- Timsort is the algorithm behind Python's sorted(). For an input that is already in ascending order, what is its running time?
- What is printed? python print(10 17 in range(0, 10 18, 2), 10 17 + 1 in range(0, 10 18, 2))
- What is printed? python def add(x, memo={}): memo[x] = len(memo) return memo print(add(5), add(7))