ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'a1b22c333' import re print(re.findall(r'\d+', s), sum(int(x) for x in re.findall(r'\d+', s)))
- A. ['1', '22', '333'] 1
- B. ['a1', 'b22', 'c333'] 356
- C. ['1', '22', '333'] 356
- D. ['1', '2', '2', '3', '3', '3'] 14
Correct answer: C. ['1', '22', '333'] 356
re.findall with \d+ collects runs of digits as strings. Adding the numbers 1, 22 and 333 gives 356.
More Python Programming questions
- What is printed? python def solve(n, memo={}): if n in memo: return memo[n] if n < 2: return n memo[n] = solve(n - 1) + solve(n - 2)…
- What is printed? python x = 7 match x: case 1 | 2: r = 'small' case int(v) if v > 5: r = f'big{v}' case : r = 'other' print(r)
- What is printed? python a = [[1, 2], [3]] b = a[:] b[1].append(4) b.append([5]) print(a, b, len(a))
- What is printed? python print(bool([]), bool([0]), bool(0.0), bool('False'), bool(None) or 'x')
- What is printed? python import heapq events = [(3, 'end'), (1, 'start'), (2, 'mid')] heapq.heapify(events) out = [] while events: t, name…
- What is printed? python word = 'level' print(word == word[::-1], 'ab' 2 == 'abab', list('ab') == ['a', 'b'], ('a',) 0 == ())