Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 83)
83.
How does the itertools.groupby() function differ from collections.Counter() when used with generators?
They are equivalent in functionality
itertools.groupby() groups consecutive elements based on a key function, while collections.Counter() counts occurrences of each element
collections.Counter() groups consecutive elements based on a key function, while itertools.groupby() counts occurrences of each element
itertools.groupby() and collections.Counter() both raise a ValueError
Answer: Option
Explanation:
itertools.groupby() groups consecutive elements based on a key function, creating subgroups. collections.Counter() counts the occurrences of each element in the entire iterable.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.