def partition_all(n):
    """Partition a collection into sub-collections (lists) of size n."""
    def generator(coll):
        temp = []
        for i, item in enumerate(coll, 1):
            temp.append(item)
            if not i % n:
                yield temp
                temp = []
        if temp:
            yield temp
    return generator