Extracting arbitrary amounts of data from a dictionary.

R

robinsiebler

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?
 
J

Jyotirmoy Bhattacharya

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.
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?

Here is an implementation using as many 'new' features of Python as I
could think of.
http://phpfi.com/247634
 
J

Jyotirmoy Bhattacharya

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.
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?

Here is an implementation using as many 'new' features of Python as I
could think of.http://phpfi.com/247634

A bit shortened and improved:
http://phpfi.com/247642
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top