← 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?
- A.groupby raises an error on unsorted data
- B.Sorting makes groupby faster
- C.groupby only groups consecutive items, so equal keys must be next to each other
- 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 →