ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
s = 'racecar level noon python' print([w for w in s.split() if w == w[::-1]], len([w for w in s.split() if w == w[::-1]]))
- A. ['racecar', 'level', 'noon'] 3
- B. ['racecar', 'level', 'noon', 'python'] 4
- C. ['racecar', 'noon'] 2
- D. ['racecar', 'level', 'noon'] 4
Correct answer: A. ['racecar', 'level', 'noon'] 3
A word is a palindrome if it equals its reverse, and 'python' is not one. The comprehension is evaluated twice, but the output counts the same three words both times.
More Python Programming questions
- What is printed? python s = 'aAbBcC' print(s.lower().count('a') + s.upper().count('A'), s.swapcase(), ''.join(c for c in s if c.islower()))
- What is printed? python s = '2024-06-01' y, m, d = map(int, s.split('-')) print(y + m + d, s.replace('-', '/'), '%02d/%02d/%04d' % (d, m…
- What is printed? python print('%d' % 1020, '%.3e' % (270), len('%d' % (2100)), '%x' % (270))
- What is printed? python print(int(float('9007199254740993')) == 9007199254740993, float('9007199254740993') == 9007199254740992.0…
- What is printed? python nums = [3, 1, 4, 1, 5, 9, 2, 6] print(sorted(nums)[len(nums) // 2], sorted(nums)[(len(nums) - 1) // 2], sum(nums)…
- What is printed? python print(sum([0.1] 3) == 0.3, sum([0.1] 3, 0.0) == 0.30000000000000004, sum([1e100, 1.0, -1e100]))