'''
Created on Oct 31, 2011
@author: rodger
'''

        
def printFirstWithLasts(namemap):
    print "Print Unique First Names with all Last Names"      
    #TODO:
    for key in namemap:
        print key + ":" + " ".join(namemap[key])






    
    
def mapNameToNumberLastNames(countmap, data):
    '''
    countmap is a map of first names to its number of occurrences
    The parameter data is a list of lists where each list is two  
    strings representing the first and last name of a person.         
    '''
    #todo:
    for name in data:
        first = name[0]
        if first in countmap:   # first is already in dictionary
            countmap[first] = countmap[first] + 1
        else:   # add to dictionary
            countmap[first] = 1   # puts in a key and its value
        






            
def  mapNameToLastNames(namemap, data):
    '''
    namemap is a map of first names to list of corresponding last names 
    The parameter data is a list of lists where each list is two  
    strings representing the first and last name of a person.    
    '''  
    #todo:
    for name in data:
        first = name[0]
        last = name[1]
        if first in namemap:   # first is already in dictionary
            namemap[first].append(last)
        else:   # add to dictionary
            namemap[first] = [last]  # puts in a key and its value
        



def  mapNameToSetLastNames(namesetmap, data):
    '''
    namemap is a map of first names to list of corresponding last names 
    The parameter data is a list of lists where each list is two  
    strings representing the first and last name of a person.    
    '''  
    for name in data:
        first = name[0]
        last = name[1]
        if first in namesetmap:   # first is already in dictionary
            namesetmap[first].add(last)
        else:   # add to dictionary
            namesetmap[first] = set([last])  # puts in a key and its value










def main():
    '''
    This is popularMap without files
    namelist is defined below
    '''
    namelist = [['Susan', 'Smith'], ['Jackie', 'Long'], ['Mary', 'White'], ['Susan', 'Brandt'], ['Jackie', 'Johnson'], ['Susan', 'Rodger'], ['Mary', 'Rodger'], ['Eric', 'Long'], ['Susan', 'Crackers'], ['Mary', 'Velios'], ['Jack', 'Frost'], ['Eric', 'Lund'], ['Susan', 'Krishnan'], ['Bala', 'Krishnamurthy'], ['Craig', 'Wills'], ['Carol', 'Wills'], ['Craig', 'Partridge'], ['Craig', 'Kim'], ['Craig', 'Matthews'], ['Bala', 'Yavatkar'], ['Susan', 'Perilous'], ['Mary', 'Evans'], ['Kara', 'Krishnan'], ['Susan', 'Smithereens']]
    print "namelist is: ", namelist 
    print

    countmap = {}
    mapNameToNumberLastNames(countmap, namelist)
    print countmap
    
    namemap = {}
    mapNameToLastNames(namemap, namelist)
    print namemap
    
    namesetmap = {}
    mapNameToSetLastNames(namesetmap, namelist)
    print namesetmap    
         
    printFirstWithLasts(namemap)
    print
    
    #TODO: Compute maxnum    
    maxnum = 0
    
    
    
    print "maximum number of corresponding last names is ",
    print maxnum
    print
    #TODO: compute lastIndex - list of names with max number last names
    lastIndex = ["none"]
   
    
    
    
    print "first name with most last names is:"
    #TODO:
 
 
 
    
if __name__ == "__main__":
    main() 
        
     
