# do it by using the state then cities dict print '-' * 10 print "Michigan has: %s" % hashmap.get(cities, hashmap.get(states, 'Michigan')) print "Florida has: %s" % hashmap.get(cities, hashmap.get(states, 'Florida')) # print every state abbreviation print '-' * 10 hashmap.list(states) # print every city in state print '-' * 10 hashmap.list(cities) print '-' * 10 state = hashmap.get(states, 'Texas') if not state: print "Sorry, no Texas." # default values using ||= with the nil result # can you do this on one line? city = hashmap.get(cities, 'TX', 'Does Not Exist') print "The city for the state 'TX' is: %s" % city print '*' * 20 print list(enumerate(states)) print list(enumerate(cities)) hashmap.list(states) print '*' * 20 hashmap.dump(states)
# print some regions print '-' * 10 print "Calabria's abbreviation is: %s" % hashmap.get(regions, 'Calabria') print "Tuscany's abbreviation is: %s" % hashmap.get(regions, 'Tuscany') # do it by using the state the cities dict print '-' * 10 print "Lazio has: %s" % hashmap.get(cities, hashmap.get(regions, 'Lazio')) print "Lombardi has: %s" % hashmap.get(cities, hashmap.get(regions, 'Lombardi')) # print every state abbreviation print '-' * 10 hashmap.list(regions) # print every city in state print '-' * 10 hashmap.list(cities) print '-' * 10 state = hashmap.get(regions, 'Sicily') if not state: print "Sorry, no Sicily." # default values using ||= with the nil result # can you do this on one line? city = hashmap.get(cities, 'SC', 'Does Not Exist') print "The city for the region 'SC' is: %s" % city hashmap.dump(cities)
print '-' * 10 print "Michigan's abbreviation is: %s" % hashmap.get(states, 'Michigan') print "Florida's abbreviation is: %s" % hashmap.get(states, 'Florida') # do it by using the state than the cities dict print '-' * 10 print "Michigan has: %s" % hashmap.get(cities, hashmap.get(states, 'Michigan')) print "Florida has: %s" % hashmap.get(cities, hashmap.get(states, 'Florida')) # print every state abbreviation print '-' * 10 hashmap.list(states) # print every city in state print '-' * 10 hashmap.list(cities) print '-' * 10 state = hashmap.get(states, 'Texas') if not state: print "Sorry, no Texas." # default values using //= with the nil result # can you do this on one line? city = hashmap.get(cities, 'TX', 'Does Not Exist') print "The city for the state 'TX' is: %s" % city hashmap.delete(states, 'Florida') hashmap.dump(states)
# do it by using the state then cities dict print '-' * 10 print "Michigan has: %s" % hashmap.get(cities, hashmap.get(states, 'Michigan')) print "Florida has: %s" % hashmap.get(cities, hashmap.get(states, 'Florida')) # print every state abbreviation print '-' * 10 hashmap.list(states) # print every city in state print '-' * 10 hashmap.list(cities) # dump city hasmap for debugging. print '-' * 10 hashmap.dump(cities) print '-' * 10 state = hashmap.get(states, 'Texas') if not state: print "Sorry, no Texas." # default values using ||= with the nil result # can you do this on one line? city = hashmap.get(cities, 'TX', 'Does Not Exist') print "The city for the state 'TX' is: %s" % city ''' study drills 1. meh. 2. https://docs.python.org/2/tutorial/datastructures.html
print "Michigan's abbreviation is: %s" % hashmap.get(states, 'Michigan') print "Florida's abbreviation is: %s" % hashmap.get(states, 'Florida') # do it by using the state then cities dict print '-' * 10 print "Michigan has: %s" % hashmap.get(cities, hashmap.get(states, 'Michigan')) print "Florida had: %s" % hashmap.get(cities, hashmap.get(states, 'Florida')) # print every states abbreviation print '-' * 10 hashmap.list(states) # print every city in state print '-' * 10 hashmap.list(cities) print '-' * 10 state = hashmap.get(states, 'Texas') if not state: print "Sorry, no Texas." # default values using ||= with the nil result # can you do this on one line? city = hashmap.get(cities, 'TX', 'Does Not Exist') print "The city for the state 'TX' is: %s" % city print hashmap.dump(states), "\n" print hashmap.dump(cities)
print '-' * 10 hashmap.list(states) # print every city in state print '-' * 10 hashmap.list(cities) print '-' * 10 state = hashmap.get(states, 'Texas') if not state: print "Sorry, no Texas." # default values using ||= with the nil result # can you do this on one line? city = hashmap.get(cities, 'TX', 'Does Not Exist') print "The city for the state 'TX' is: %s" % city print '-' * 10 #hashmap.dump(cities) print '-' * 10 hashmap.dump(states, cities)
print '-' * 10 print "Michigan's abbreviation is: %s" % hashmap.get(states, 'Michigan') print "Florida's abbreviation is: %s" % hashmap.get(states, 'Florida') print '-' * 10 print "Michigan has: %s" % hashmap.get(cities, hashmap.get(states, 'Michigan')) print "Florida has: %s" % hashmap.get(cities, hashmap.get(states, 'Florida')) print '-' * 10 hashmap.list(states) print '-' * 10 hashmap.list(cities) print '-' * 10 state = hashmap.get(states, 'Texas') if not state: print "Sorry, no Texas." city = hashmap.get(cities, 'TX', 'Does Not Exist') print "The city for the state 'TX' is: %s" % city back_cities = hashmap.dump(cities) hashmap.delete(cities, "NY") print '-' * 10 hashmap.list(cities) print '-' * 10 hashmap.list(back_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 '*' * 20 toMap = [] hashmap.dump(cities, toMap) print toMap hashmap.set(toMap, 'CA', '*****************') hashmap.list(toMap) print '*' * 20 # print out some cities print '-' * 10 print "NY State has: %s" % hashmap.get(cities, 'NY') print 'OR State has: %s' % hashmap.get(cities, 'OR') # print some states print '-' * 10 print "Michigan's abbreviation is: %s" % hashmap.get(states, 'Michigan') print "Florida's abbreviation is: %s" % hashmap.get(states, 'Florida')
assert (hashmap.get(traits,hashmap.get(races,'Gnome'))), 'Gnomes have no traits' # prints of dict contents #print "Tieflings have: %s " % hashmap.get(traits, hashmap.get(races, 'Tiefling')) #print "Gnomes have: %s " % hashmap.get(traits, hashmap.get(races, 'Gnome')) # print every state abbreviation print '-' * 10 hashmap.list(races) # print every city in state print '-' * 10 hashmap.list(traits) print '-' * 10 # asserting race #assert hashmap.get(races,'Kobold'), 'There are no Kobold races' #race = hashmap.get(races, 'Kobold') #if not race: # print "Sorry, no Kobolds." # default values using || = with the nil result # can you do this on one line? #trait = hashmap.get(traits, 'KBD', 'Don\'t Exist') #assert hashmap.get(traits,'KBD'), 'No traits exist for KBD' #print "The traits for the kobolds 'KBD' is : %s " % trait print "The total items of races are : %d " % len(races) #print "A string of this dictionary is: %s " % str(races) print "Dumping.." hashmap.dump(races)
print '-' * 10 print "Michigan's abbreviation is: %s" % hashmap.get(states, 'Michigan') print "Florida's abbreviation is: %s" % hashmap.get(states, 'Florida') # do it by using the state then cities dict print '-' * 10 print "Michigan has: %s" % hashmap.get(cities, hashmap.get(states, 'Michigan')) print "Florida had: %s" % hashmap.get(cities, hashmap.get(states, 'Florida')) # print every states abbreviation print '-' * 10 hashmap.list(states) # print every city in state print '-' * 10 hashmap.list(cities) print '-' * 10 state = hashmap.get(states, 'Texas') if not state: print "Sorry, no Texas." # default values using ||= with the nil result # can you do this on one line? city = hashmap.get(cities, 'TX', 'Does Not Exist') print "The city for the state 'TX' is: %s" % city print hashmap.dump(states), "\n" print hashmap.dump(cities)
# print out some cities print '-' * 10 assert hashmap.get(cities, 'NY') == 'New York' assert hashmap.get(cities, 'OR') == 'Portland' # print some states print '-' * 10 assert hashmap.get(states, 'Michigan') == 'MI' assert hashmap.get(states, 'Florida') == 'FL' # do it by using the state then cities dict print '-' * 10 assert hashmap.get(cities, hashmap.get(states, 'Michigan')) == 'Detroit' assert hashmap.get(cities, hashmap.get(states, 'Florida')) == 'Jacksonville' # print every state abbreviation print '-' * 10 hashmap.list(states) hashmap.dump(states) # print every city in state print '-' * 10 hashmap.list(cities) hashmap.dump(cities) print '-' * 10 assert hashmap.get(states, 'Texas') != 'TX', "Sorry, no Texas." # default values using ||= with the nil result # can you do this on one line? assert hashmap.get(cities, 'TX') == 'Dallas', 'Does Not Exist'
import hashmap # The tests that it will work jazz = hashmap.new() hashmap.set(jazz, 'Miles Davis', 'Flamenco Sketches') # confirms set will replace previous one hashmap.set(jazz, 'Miles Davis', 'Kind of Blue') hashmap.set(jazz, 'Duke Ellington', 'Beginning To See The Light') hashmap.set(jazz, 'Billy Strayhorn', 'Lush Life') print "---- List Test ----" hashmap.list(jazz) print "---- Dump Test ----" hashmap.dump(jazz) print "---- Get Test ----" print hashmap.get(jazz, 'Miles Davis') print hashmap.get(jazz, 'Duke Ellington') print hashmap.get(jazz, 'Billy Strayhorn') print "---- Delete Test ----" print "** Goodbye Miles" hashmap.delete(jazz, "Miles Davis") hashmap.list(jazz) print "** Goodbye Duke" hashmap.delete(jazz, "Duke Ellington") hashmap.list(jazz)