ex39_hashmap.set(states, 'Michigan', 'MI') # create a basic set of states and some cities in them cities = ex39_hashmap.new() ex39_hashmap.set(cities, 'CA', 'San Francisco') ex39_hashmap.set(cities, 'MI', 'Detroit') ex39_hashmap.set(cities, 'FL', 'Jacksonville') # add some more cities ex39_hashmap.set(cities, 'NY', 'New York') ex39_hashmap.set(cities, 'OR', 'Portland') # print out some cities print '-' * 10 print "NY State has: %s" % ex39_hashmap.get(cities, 'NY') print "OR State has: %s" % ex39_hashmap.get(cities, 'OR') # print some states print '-' * 10 print "Michigan's abbreviation is: %s" % ex39_hashmap.get(states, 'Michigan') print "Florida's abbreviation is: %s" % ex39_hashmap.get(states, 'Florida') # do it by using the state then cities dict print '-' * 10 print "Michigan has: %s" % ex39_hashmap.get(cities, ex39_hashmap.get(states, 'Michigan')) print "Florida has: %s" % ex39_hashmap.get(cities, ex39_hashmap.get(states, 'Florida')) # print every state abbreviation print '-' * 10 ex39_hashmap.list(states)
import ex39_hashmap # The tests that it will work jazz = ex39_hashmap.new() ex39_hashmap.set(jazz, 'Miles Davis', 'Flamenco Sketches') # confirm set will replace previous one ex39_hashmap.set(jazz, 'Miles Davis', 'Kind of Blue') ex39_hashmap.set(jazz, 'Duke Ellington', 'Beginning To See The Light') ex39_hashmap.set(jazz, 'Billy Strayhorn', 'Lush Life') print "---- List Test ----" ex39_hashmap.list(jazz) print "---- Get Test ----" print ex39_hashmap.get(jazz, 'Miles Davis') print ex39_hashmap.get(jazz, 'Duke Ellington') print ex39_hashmap.get(jazz, 'Billy Strayhorn') print "---- Delete Test ----" print "** Goodbye Miles" ex39_hashmap.delete(jazz, "Miles Davis") ex39_hashmap.list(jazz) print "** Goodbye Duke" ex39_hashmap.delete(jazz, "Duke Ellington") ex39_hashmap.list(jazz) print "** Goodbye Billy" ex39_hashmap.delete(jazz, "Billy Strayhorn") ex39_hashmap.list(jazz)
ex39_hashmap.set(states, 'New York', 'NY') ex39_hashmap.set(states, 'Michigan', 'MI') # create a basic set of states and some cities in them cities = ex39_hashmap.new(10) ex39_hashmap.set(cities, 'CA', 'San Francisco') ex39_hashmap.set(cities, 'MI', 'Detroit') ex39_hashmap.set(cities, 'FL', 'Jacksonville') # add some more cities ex39_hashmap.set(cities, 'NY', 'New York') ex39_hashmap.set(cities, 'OR', 'Portland') # print out some cities print '-' * 10 print "NY State has: %s" % ex39_hashmap.get(cities, 'NY') print "OR State has: %s" % ex39_hashmap.get(cities, 'OR') # print some states print '-' * 10 print "Michigan's abbreviation is: %s" % ex39_hashmap.get(states, 'Michigan') print "Florida's abbreviation is: %s" % ex39_hashmap.get(states, 'Florida') # do it by using the state then cities dict print '-' * 10 print "Michigan has: %s" % ex39_hashmap.get( cities, ex39_hashmap.get(states, 'Michigan')) print "Florida has: %s" % ex39_hashmap.get(cities, ex39_hashmap.get(states, 'Florida')) # print every state abbreviation
# -*- coding: utf-8 -*- import ex39_hashmap provinces = ex39_hashmap.new() ex39_hashmap.set(provinces, '浙江', '浙') ex39_hashmap.set(provinces, '江苏', '苏') ex39_hashmap.set(provinces, '安徽', '皖') ex39_hashmap.set(provinces, '广东', '粤') ex39_hashmap.set(provinces, '上海', '沪') ex39_hashmap.list(provinces) ex39_hashmap.get(provinces, '江苏') cities = ex39_hashmap.new() ex39_hashmap.set(cities, '浙', '杭州') ex39_hashmap.set(cities, '苏', '扬州') ex39_hashmap.set(cities, '皖', '合肥') ex39_hashmap.set(cities, '粤', '深圳') ex39_hashmap.set(cities, '沪', '静安') ex39_hashmap.list(cities) ex39_hashmap.delete(cities, '浙') ex39_hashmap.list(cities) ex39_hashmap.get(cities, '苏') ex39_hashmap.get(cities, ex39_hashmap.get(provinces, '上海'))
hm.set(states, 'Michigan', 'MI') # create a basic set of states and some cities in them cities = hm.new() hm.set(cities, 'CA', 'San Francisco') hm.set(cities, 'MI', 'Detroit') hm.set(cities, 'FL', 'Jacksonville') # add some more cities hm.set(cities, 'NY', 'New York') hm.set(cities, 'OR', 'Portland') # print out some cities print '-' * 10 print "NY State has: %s" % hm.get(cities, 'NY') print "OR State has: %s" % hm.get(cities, 'OR') # print some states print '-' * 10 print "Michigan's abbreviation is: %s" % hm.get(states, 'Michigan') print "Florida's abbreviation is: %s" % hm.get(states, 'Florida') # do it by using the state then cities dict print '-' * 10 hm.list(states) # print every city in state print '-' * 10 hm.list(cities)
hashmap.set(states, 'New York', 'NY') hashmap.set(states, 'Michigan', 'MI') # create a basic set of states and some cities in them cities = hashmap.new() hashmap.set(cities, 'CA', 'San Francisco') hashmap.set(cities, 'MI', 'Detroit') hashmap.set(cities, 'FL', 'Jacksonville') # add some more cities hashmap.set(cities, 'NY', 'New York') hashmap.set(cities, 'OR', 'Portland') # print out some cities print '-' * 10 print "NY State has: ", hashmap.get(cities, 'NY') print "OR State has: ", hashmap.get(cities, 'OR') # print some states print '-' * 10 print "Michigan's abbreviation is: ", hashmap.get(states, 'Michigan') print "Florida's abbreviation is: ", hashmap.get(states, 'Florida') # do it by using the state then cities dict print '-' * 10 print "Michigan has: ", hashmap.get(cities, hashmap.get(states, 'Michigan')) print "Florida has:", hashmap.get(cities, hashmap.get(states, 'Florida')) # print every state abbreviation print '-' * 10 hashmap.list(states)
ex39_hashmap.set(states, "New York", "NY") ex39_hashmap.set(states, "Michigan", "MI") # create new dict of abbrev to cities cities = ex39_hashmap.new() ex39_hashmap.set(cities, "CA", "San Francisco") ex39_hashmap.set(cities, "MI", "Detroit") ex39_hashmap.set(cities, "FL", "Jacksonville") # add more cities ex39_hashmap.set(cities, "NY", "New York") ex39_hashmap.set(cities, "OR", "Portland") # print cities print "-" * 10 print "NY state has: %s" % ex39_hashmap.get(cities, "NY") print "OR state has: %s" % ex39_hashmap.get(cities, "OR") # print state and abbrev print "-" * 10 print "The abbreviation of Michigan is %s" % ex39_hashmap.get(states, "Michigan") print "The abbreviation of Florida is %s" % ex39_hashmap.get(states, "Florida") # print using two dicts combined # do it by using the state then cities dict print "-" * 10 print "Michigan has: %s" % ex39_hashmap.get(cities, ex39_hashmap.get(states, "Michigan")) print "Florida has: %s" % ex39_hashmap.get(cities, ex39_hashmap.get(states, "Florida")) # print every state abbreviation print "-" * 10