'''
Created on Nov 2, 2011

@author: rodger
'''

def createDictionary(songmap, songs):
    listsongs =[]
    #first get data in format of lists of lists of song and position
    for item in songs:
        mylist = item.split(":")
        listsongs.append((mylist[0],0))
        listsongs.append((mylist[1],1))
        listsongs.append((mylist[2],2))    
    print listsongs      
    
    # build the map
    for item in listsongs:
        if item[0] in songmap:  # song in map already
            counts = songmap[item[0]]     # list of 3 counts
            counts[item[1]] +=1  # update that count
        elif item[1] == 0:
            songmap[item[0]] = [1,0,0]  # first place song
        elif item[1] == 1:
            songmap[item[0]] = [0,1,0]  # second place song
        else:
            songmap[item[0]] = [0,0,1]   # third place song
        
            
#problem
songs = ["Hey Jude:Let it be:Day Tripper",
"Let it be:Drive my car:Hey Jude",
"I want to hold your hand:Day Tripper:Help!",
"Born to run:Thunder road:She's the one",
"Hungry heart:The river:Born to run",
"The river:Thunder road:Drive my car", 
"Angie:Start me up:Ruby Tuesday",
"Born to run:Angie:Drive my car"]

print songs
songmap = {}
createDictionary(songmap, songs)
print songmap

maxcount = 0
maxsong = ""
# most popular song unweighted
for (key,value) in songmap.iteritems():
    total = sum(value)
    if total > maxcount:
        maxcount = total
        maxsong = key
        
print "maxcount and max song", maxcount, " ", maxsong
    
