ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
s = 'aaaa'
print(s.count('aa'), s.replace('aa', 'b'), 'a,,b'.split(','), ' x y '.split(' '))- A. 2 bb ['a', 'bb'] ['x', 'y']
- B. 2 bb ['a', '', 'b'] ['x', 'yy']
- C. 2 bb ['a', '', 'b'] ['', 'x', '', 'y', '']
- D. 3 bb ['a', '', 'b'] ['', 'x', '', 'y', '']
Correct answer: C. 2 bb ['a', '', 'b'] ['', 'x', '', 'y', '']
count and replace scan left to right without overlap, so aaaa has two aa pairs. split with an explicit separator keeps the empty fields between separators.
More Python Programming questions
- What is printed? python import itertools print([''.join(p) for p in itertools.permutations('abc', 2)][:4])
- What is printed? python import itertools print(len(list(itertools.combinationswithreplacement(range(5), 3))))
- What is printed? python import itertools print(sum(1 for t in itertools.product('01', repeat=10) if t.count('1') == 3))
- What is printed? python import itertools g = itertools.groupby('aab') k, grp = next(g) next(g) print(k, list(grp))
- What is printed? python import itertools g = iter(range(10)) print(list(itertools.islice(g, 2, 7, 2)), next(g))
- What is printed? python import itertools print(list(itertools.ziplongest('ab', 'xyz', fillvalue='-')))