[Tutor] Chunking list/array data?

Sarah Hembree sarah123ed at gmail.com
Wed Aug 21 21:26:34 EDT 2019


How do you chunk data? We came up with the below snippet. It works (with
integer list data) for our needs, but it seems so clunky.

    def _chunks(lst: list, size: int) -> list:
        return  [lst[x:x+size] for x in range(0, len(lst), size)]

What do you do? Also, what about doing this lazily so as to keep memory
drag at a minimum?


--- We not only inherit the Earth from our Ancestors, we borrow it from our
Children. Aspire to grace.


More information about the Tutor mailing list