Selecting a subset of the data from a list I have a list called all_dates which contains timestamps for a number of days (hourly). I wanted to select each day (i.e every 24 items in the list) and pass it to a function.

Here is my implementation that works:

count = 0
while count &lt; len(all_dates)-1:
    day_list = [all_dates[count]]
    for i in xrange(23):
        count += 1
        day_list.append(all_dates[count])
    print_dates(day_list)
    count += 1


I know this is probably not the best way it can be done in Python so I wanted some help to improve my implementation.
It looks like you want to split a large list of items to equal sized chunks.
I suggest using a helper generator:

def chunks(items, size):
    for start in range(0, len(items), size):
        yield items[start:start+size]


Using this, your main task becomes simply:

for day_list in chunks(all_dates, 24):
    print_dates(day_list)