🎙 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 5 of 10

Why should you usually sort before using groupby?

Why should you usually sort before using groupby?

  1. A.groupby raises an error on unsorted data
  2. B.Sorting makes groupby faster
  3. C.groupby only groups consecutive items, so equal keys must be next to each other
  4. D.groupby returns the items sorted anyway
Answer & explanation

Correct answer: groupby only groups consecutive items, so equal keys must be next to each other

Without sorting, the same key can appear as several separate groups.

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 →