Example #1
0
import ex39_hashmap

# create a mapping of state to abbreviation
states = ex39_hashmap.new()
ex39_hashmap.set(states, 'Oregon', 'OR')
ex39_hashmap.set(states, 'Florida', 'FL')
ex39_hashmap.set(states, 'California', 'CA')
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()
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')
# -*- coding: utf-8 -*-

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"
Example #3
0
# --coding: utf-8--

import ex39_hashmap

# create a mapping of state to abbreviation
states = ex39_hashmap.new(10)
ex39_hashmap.set(states, 'Oregon', 'OR')
ex39_hashmap.set(states, 'Florida', 'FL')
ex39_hashmap.set(states, 'California', 'CA')
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')
Example #4
0
# -*- 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, '上海'))
Example #5
0
import ex39_hashmap as hm

# create a mapping of state to abbreviation
states = hm.new()
hm.set(states, 'Oregon', 'OR')
hm.set(states, 'Florida', 'FL')
hm.set(states, 'California', 'CA')
hm.set(states, 'New York', 'NY')
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')
import ex39_hashmap as hashmap

# create a mapping of states
states = hashmap.new()
hashmap.set(states, 'Oregon', 'OR')
hashmap.set(states, 'Florida', 'FL')
hashmap.set(states, 'California', 'CA')
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
Example #7
0
__author__ = 'rudragouda'

import ex39_hashmap

# create a mapping of state to abbreviation
states = ex39_hashmap.new()
ex39_hashmap.set(states, 'Oregon', 'OR')
ex39_hashmap.set(states, 'Florida', 'FL')
ex39_hashmap.set(states, 'California', 'CA')
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()
# 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')