Suppose I have a table with a article headers, author, and also a publication date, I retrieve all of the ones that are published after July 1st, - but now I want to iterate through not the article headers individually, but through sets of all the articles published on each day, what's the best and most pythonic way to build this list. Can it be done in the sqlite query?
Edit: I don't actually have a table with articles in sqlite3, but let's suppose I did. And suppose the table articles is organized with:
title TEXT, author TEXT, publisher TEXT, date DATETIME
The articles might be fetched like so:
cursor.execute("SELECT * FROM articles where date > ?", \
(datetime.datetime(2014, 07, 01),))
and could be grouped by (Following Holdenweb's answer below):
itertools.groupby(cursor.fetchall(), lambda x: datetime.strptime(x[3], '%Y-%m-%d %H:%M:%S.%f').day)
which will give a tuple of (day, group), and can be iterated over in the manner described below.