Пример #1
0
# -*- 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"
Пример #2
0
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)

# print every city in state
print '-' * 10
ex39_hashmap.list(cities)

print '-' * 10
state = ex39_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 = ex39_hashmap.get(cities, 'TX', 'Does Not Exist')
print "The city for the state 'TX' is: %s" % city
Пример #3
0
# 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)

# print every city in state
print '-' * 10
ex39_hashmap.list(cities)

print '-' * 10
state = ex39_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 = ex39_hashmap.get(cities, 'TX', 'Does Not Exist')
print "The city for state 'TX' is: %s" % city
Пример #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, '上海'))
Пример #5
0
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)

print '-' * 10
state = hm.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 = hm.get(cities, 'TX', 'Does Not Exist')
print "The city for the state 'TX' is: %s" % city
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)

# 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