I have a long list with N elements. I would like to iterate the long list, but picking K elements at every iteration (or less if there are less than K in the long list). What would be the most elegant way to do it?
for short_list_K in long_list_N:
# len(short_list_K) <= K
The itertools module documentation provides this recipe:
Which can be used like so: