'''
Created on Nov 2, 2014

@author: rodger
'''
# dictionary of schools and how many students at an event
# are from each school

d = {'duke':30, 'unc':50, 'ncsu':40}

print "d.values()", d.values()
print "d.keys()", d.keys()
d['duke'] = 80
d.update({'ecu':40, 'uncc':70})
print "d.values()", d.values()

# what is the difference between these 3?

print "d.items()", d.items()
print "d.iteritems()", d.iteritems()
print "d", d

# problem - using the dictionary from above, write Python code 
# to determine how many schools have more than 40 attendees?

count = 0
for (key,value) in d.items():
    if value > 40:
        count +=1
print "Number of schools with more than 40 attendees is ", count


# problem - Using the dictionary from above, write python code to determine 
# which schools have more than 40 attendees - give a list

schools = []


print "Schools with more than 40 attendees is ", schools  


# problem -  Create a new dictionary mapping attendance numbers to list of schools
# with that attendance number
d = {'duke':30, 'unc':50, 'ncsu':40, 'wfu':50, 'ecu': 80, 'meridith':30, 'clemson':80, 'gatech':50, 'uva':120, 'vtech':110} 
print "d is", d 

d2 = {}
for (school,num) in d.items():
    if num not in d2:
        d2[num] = [school]
    else: 
        d2[num].append(school)
print "d2 is", d2



# problem create a new dictionary mapping groups of 50 attendees 0-49, 50-99, etc
d3 = {}
for (school,num) in d.iteritems():
    newnum = num/50
    keylow = newnum*50
    keyhigh = newnum*50 +49
    key = str(keylow) + "-" + str(keyhigh) # want keys to be "0:49", "50-99", etc

# #   This uses 0 as the key for "0-49", 1 for "50-99", etc
#     if newnum not in d3:
#         d3[newnum] = [school]
#     else:
#         d3[newnum].append(school)

# This builds a string for the key instead that is "0-49", "50-99", etc
    if newnum not in d3:
        d3[key] = [school]
    else:
        d3[key].append(school)


print d3
