itertools.groupby collects together contiguous items with the same key.
If you want all items with the same key, you have to sort self.data
first.
for mid, group in itertools.groupby(
sorted(self.data,key=operator.itemgetter(1)), key=operator.itemgetter(1)):
More Related Contents:
- How can I match up permutations of a long list with a shorter list (according to the length of the shorter list)? [duplicate]
- Prevent memory error in itertools.permutation
- python all possible combinations of 0,1 of length k [duplicate]
- Using itertools.product and want to seed a value
- How to summarize on different groupby combinations?
- Does itertools.product evaluate its arguments lazily?
- Numpy equivalent of itertools.product [duplicate]
- How to check if string input is a number?
- How does asyncio actually work?
- Python setup.py develop vs install
- How to set environment variables in PyCharm?
- ImportError after successful pip installation [duplicate]
- Do Python for loops work by reference?
- ValueError: numpy.dtype has the wrong size, try recompiling
- Python module with a dash, or hyphen (-) in its name
- Does tkinter have a table widget?
- Using a Python subprocess call to invoke a Python script
- Is there a difference between continue and pass in a for loop in Python?
- Python Pandas: Is Order Preserved When Using groupby() and agg()?
- Python min function with a list of objects
- How to modify the innerHTML of a contenteditable element
- Convert list of ASCII codes to string (byte array) in Python
- Using Django database layer outside of Django?
- Understanding __init_subclass__
- pandas divide row value by aggregated sum with a condition set by other cell
- Python: Rename duplicates in list with progressive numbers without sorting list
- Why does this take so long to match? Is it a bug?
- “unpacking” a passed dictionary into the function’s name space in Python?
- Mapping dictionary value to list
- Python Global Interpreter Lock (GIL) workaround on multi-core systems using taskset on Linux?