ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
words = ['apple', 'bob', 'kayak', 'tree'] print([w for w in words if w == w[::-1]], len(words[1:3]))
- A. ['bob', 'kayak'] 2
- B. ['bob'] 2
- C. ['apple', 'bob', 'kayak'] 3
- D. ['kayak'] 3
Correct answer: A. ['bob', 'kayak'] 2
A palindrome reads the same backwards. bob and kayak qualify. words[1:3] has two items.
More Python Programming questions
- What is printed? python lines = ['3 4', '10 20'] pairs = [tuple(map(int, ln.split())) for ln in lines] print(pairs, sum(a b for a, b in…
- What is printed? python from math import comb print(comb(4, 2) comb(4, 2), comb(8, 4) - comb(8, 3))
- What is printed? python print(list(map(lambda p: p[0] + p[1], zip([1, 2], [10, 20, 30]))))
- What is printed? python s = 'a1b2c3' letters = ''.join(c for c in s if c.isalpha()) digits = sum(int(c) for c in s if c.isdigit())…
- What is printed? python def f(a, args, key=None, kw): return (a, args, key, sorted(kw)) print(f(1, 2, 3, key='k', z=0, y=9))
- What is printed? python print(bool(0.0), bool(-0.0), bool(1e-300), bool(float('nan')))