DeaD_EyE icon

paginate

DeaD_EyE | PRO | 06/16/22 01:53:29 PM UTC | 0 ⭐ | 1427 👁️ | Never ⏰ | []
Python |

390 B

|

None

|

0 👍

/

0 👎

from functools import partial
from itertools import islice
 
def paginate(iterable, page_size):
    get_pages = partial(islice, iter(iterable), page_size)
    while data := list(get_pages()):
        yield data
 
 
pages = range(10) # Iterable
 
# paginate works with generators, iterators and
# iterables. Ordinary lists are also iterable.
for pages in paginate(pages, 3):
    print(pages)
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎