ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = 'a,b;c d'
print(x.replace(',', ' ').replace(';', ' ').split(), x.replace(',', ' ').split(' '))- A. ['a', 'b', 'c', 'd'] ['a', 'b;c', 'd']
- B. ['a', 'b', 'c', 'd'] ['a', 'b', 'e']
- C. ['a', 'b', 'c d'] ['a', 'b', 'f']
- D. ['a', 'b', 'c', 'd'] ['a', 'b;c d', 'g']
Correct answer: A. ['a', 'b', 'c', 'd'] ['a', 'b;c', 'd']
split() with no argument splits on any whitespace, so the first list has four items. The second replace turns only the commas into spaces, so the semicolon stays inside one piece, and split(' ') breaks only on single spaces.
More Python Programming questions
- What is printed? python import string print(string.asciilowercase.index('z') - string.asciiuppercase.index('A'), len(string.digits +…
- What is printed? python a = [5, 1, 4] b = a a = sorted(a) c = a.copy() c.reverse() print(a, b, c)
- What is printed? python def f(a, b=[]): b.append(a) return len(b) print(f(1), f(2, []), f(3))
- What is printed? python values = [4, 8, 15, 16, 23, 42] print(bisect.bisect(values, 15) if False else 0, [v for v in values if v % 2 and v…
- What is printed? python import heapq h = [5, 1, 4] print(heapq.heappushpop(h, 0), heapq.heappushpop([], 7), sorted(h))
- What is printed? python def walk(n): if n == 0: return [] return [n] + walk(n - 1) print(walk(3), len(walk(500)))