Extracting arbitrary amounts of data from a dictionary.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robinsiebler@gmail.com

    #1

    Extracting arbitrary amounts of data from a dictionary.

    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?

  • Jyotirmoy Bhattacharya

    #2
    Re: Extracting arbitrary amounts of data from a dictionary.

    On Jul 6, 12:31 am, robinsieb...@gm ail.com wrote:
    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.


    Comment

    • Jyotirmoy Bhattacharya

      #3
      Re: Extracting arbitrary amounts of data from a dictionary.

      On Jul 6, 2:21 am, Jyotirmoy Bhattacharya <jmoy.mate...@g mail.com>
      wrote:
      On Jul 6, 12:31 am, robinsieb...@gm ail.com wrote:
      >
      >
      >
      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:


      Comment

      Working...