Extracting arbitrary amounts of data from a dictionary.

robinsiebler at gmail.com robinsiebler at gmail.com
Thu Jul 5 21:31:56 CEST 2007

I had nothing better to do, so I thought I would make a database that
contained the songs played on the internet radio station I listen to
(hardradio.com) so I could see how many differents songs/artists they
played.  I stored the data like this:

    dates = {} #; year = {}; week = {}; date = {}; artist = []; song =
#    dates = {'2007': {'25': {'06/23/07': {'aerosmith': [{'sweet
emotion': 1}, {'dream on': 2}],
#                                                    'Metallica':
[{'Fade to Black': 1}, {'Master of Puppets': 1}]},
#                 'last_song': 'Master of Puppets'}}}

So I end up with a the number of times any given song by a given
artist is played in a day.  Want I want to do is to be able to print
out a report for X number of weeks and I am trying to determine the
best way to interate through the 'week' key of the dictionary.

For example, this is week 27, the dictonary has 6 'week' keys and I
want the data from the last 3 weeks.  Is this the best way to iterate
through the dictionary?

       for date in dates[year][week].keys()[-3]:

Or is there a better way with all the new features that have been
added to Python?

More information about the Python-list mailing list