← Quiz: TOC Basics: all 10 questions
Quiz: TOC Basics · Question 9 of 10
What does this print? (code)
What does this print?
from itertools import product
L = ["".join(t) for n in range(4) for t in product("ab", repeat=n)]
print(len([w for w in L if w == w[::-1]]))
- A.7
- B.8
- C.9
- D.15
Answer & explanation
Correct answer: 9
The palindromes of length at most 3 are ε, a, b, aa, bb, aaa, aba, bab and bbb.
Can you get the rest right without peeking?
Take the timed Quiz: TOC Basics quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →