🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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]]))
  1. A.7
  2. B.8
  3. C.9
  4. 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 →