🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: itertools and functools: all 10 questions

Quiz: itertools and functools · Question 6 of 10

What does this print? (code)

What does this print?

from itertools import groupby
print([k for k, g in groupby("aabba")])
  1. A.['a', 'b']
  2. B.['a', 'b', 'a']
  3. C.['aa', 'bb', 'a']
  4. D.['a', 'a', 'b', 'b', 'a']
Answer & explanation

Correct answer: ['a', 'b', 'a']

Three runs of consecutive equal letters: aa, bb, a.

Can you get the rest right without peeking?

Take the timed Quiz: itertools and functools quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →