def writeToTrain(wd):
    fname = wd.split('.')[0]
    f1 = open("trainInstances/"+fname+"_train.instance","r")
    context = False
    dict1=hashmap.new()
    sensids = []
    for line in f1:
        if line.startswith("<answer instance"):
            split_for_sensid = line.split()[2]
            #print(split_for_sensid)
            sid = split_for_sensid[9:-3]
            if sid not in sensids:
                sensids.append(sid)
            continue
        if line.startswith("<context"):
            context = True
            continue
        if line.startswith("</context"):
            context = False
            continue
        if context and (not line.startswith("<instance")) and (not line.startswith("</instance")) and (not line.startswith("<answer")):
            newList = []
            list1 = hashmap.get(dict1,sid)
            splitLine = line.split()
            if list1:
                hashmap.delete(dict1,sid)
                for word in splitLine:
                    #print(word)
                    if word not in list1:
                        list1.append(word.lower())
                hashmap.set(dict1,sid,list1)
            else:
                for word in splitLine:
                    if word not in newList:
                        #print(word)
                        newList.append(word.lower())
                hashmap.set(dict1,sid,newList)
    cleanAndWrite(fname,dict1,sensids)
def cleanAndWrite(wd,hmap,sensids):
    file = open("pickleOutput/" + wd + "_output.p","wb")
    mainDict = {}
    tempList = []
    for sid in sensids: #outer loop for going through all sense-ids
        dict1={}
        list1 = hashmap.get(hmap,sid)
        for othersid in sensids: #inner for loop 
            if sid==othersid:   #if both sense-ids are same, move forward
                continue
            else:
                l1 = hashmap.get(hmap,othersid)
                hashmap.delete(hmap,othersid)
                if list1:
                    for word in list1:  #check if word from outer loop is in inner
                        dict1[word]=1
                        #print(word)
                        if l1:
                            if word in l1:
                                dict1[word]=dict1[word]+1
                                l1.remove(word)
                    hashmap.set(hmap,othersid,l1)
        dict2 = dict1.copy()
        for key in dict2:
            if dict2[key]>1:
                del dict1[key]
        mainDict[sid] = dict1.keys()
        tempList.append(sid)
        for item in dict1.keys():
            tempList.append(item)
        tempList.append("-")
    #print(mainDict["bank%1:17:02::"])
    #print(mainDict)
    #print(tempList)
    pickle.dump(tempList,file)
    file.close()
import hashmap

#create a mapping of state to abbreviation
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: %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'))
示例#4
0
import hashmap

# create a mapping of state to abbreviation
regions = hashmap.new()
hashmap.set(regions, 'Calabria', 'CB')
hashmap.set(regions, 'Campania', 'CM')
hashmap.set(regions, 'Lazio', 'LZ')
hashmap.set(regions, 'Lombardi', 'LB')
hashmap.set(regions, 'Tuscany', "TC")

# create a basic set of regions and add some cities in them
cities = hashmap.new()
hashmap.set(cities, 'CB', 'Catanzaro')
hashmap.set(cities, 'CP', 'Naples')
hashmap.set(cities, 'LZ', 'Rome')

# add some more cities
hashmap.set(cities, 'LB', 'Milan')
hashmap.set(cities, 'TC', 'Florence')


# print out some cities
print '-' * 10
print "CB has: %s" % hashmap.get(cities, 'CB')
print "LZ has: %s" % hashmap.get(cities, 'LZ')

# 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')
# -*- coding: gb2312 -*-
import hashmap

# create a mapping of state to abbreviation
states = hashmap.new()
hashmap.set(states, '四川', '川')
hashmap.set(states, '浙江', '浙')
hashmap.set(states, '贵州', '黔')
hashmap.set(states, '重庆', '渝')
hashmap.set(states, '云南', '滇')

# create a basic set of states and some cities in them
cities = hashmap.new()
hashmap.set(cities, '川', '成都')
hashmap.set(cities, '浙', '杭州')
hashmap.set(cities, '黔', '贵阳')

# add some more cities
hashmap.set(cities, '渝', '江北')
hashmap.set(cities, '滇', '丽江')


# print out some cities
print '-' * 10
print "川 有: %s" % hashmap.get(cities, '川')
print "滇 有: %s" % hashmap.get(cities, '滇')

# print some states
print '-' * 10
print "重庆的简称是: %s" % hashmap.get(states, '重庆')
print "浙江的简称是: %s" % hashmap.get(states, '浙江')
import hashmap

# The tests that 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 "---- 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)

print "**Goodbye Billy"
hashmap.delete(jazz, "Billy Strayhorn")
hashmap.list(jazz)
示例#7
0
#These examples are included online but not in the hardcopy of LPTHW-3E
import hashmap
import collections

# create a mapping of state to abbreviation
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')
hashmap.set(states, 'Arizona', 'AZ')
hashmap.set(states, 'Nevada', 'NV')

# 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')
hashmap.set(cities, 'NV', 'Las Vegas')
hashmap.set(cities, 'AZ', 'Phoenix')

# 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: %s" % hashmap.get(cities, 'NY')
print "OR State has: %s" % hashmap.get(cities, 'OR')
示例#8
0
import hashmap

states = hashmap.new()
hashmap.set(states, "Galati", "GL")
hashmap.set(states, "Ilfov", "IF")
hashmap.set(states, "Alba", "AB")
hashmap.set(states, "Suceava", "SV")
hashmap.set(states, "Braila", "BR")

cities = hashmap.new()
hashmap.set(cities, "GL", "Galati")
hashmap.set(cities, "IF", "Bucuresti")
hashmap.set(cities, "AB", "Alba Iulia")
hashmap.set(cities, "SV", "Siret")
hashmap.set(cities, "BR", "Ianca")

print "-" * 10
print "GL State has: %s" % hashmap.get(cities, "GL")
print "BR State has: %s" % hashmap.get(cities, "BR")

print "-" * 10
print "Suceava has: %s" % hashmap.get(states, "Suceava")
print "Alba has: %s" % hashmap.get(states, "Alba")

print "-" * 10
hashmap.list(states)

print "-" * 10
hashmap.list(cities)

print "-" * 10
import hashmap

# create a mapping of state to abbreviation
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: %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")
示例#10
0
import unittest
import hashmap


# create a mapping of state to abbreviation
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')
hashmap.set(states, 'Oregon', 'US')
hashmap.set(states, 'Florida', 'US')
hashmap.set(states, 'California', 'US')
hashmap.set(states, 'New York', 'US')
hashmap.set(states, 'Michigan', 'US')
# create a basic set of states and some cities in them
cities = hashmap.new()
hashmap.set(cities, 'CA', 'San Francisco')
hashmap.set(cities, 'CA', 'San Diego')
hashmap.set(cities, 'MI', 'Detroit')
hashmap.set(cities, 'MI', 'Freezing')
hashmap.set(cities, 'FL', 'Jacksonville')
hashmap.set(cities, 'FL', 'Tampa Bay')
hashmap.set(cities, 'FL', 'Miami')
# add some more cities
hashmap.set(cities, 'NY', 'New York')
hashmap.set(cities, 'OR', 'Portland')
hashmap.set(cities, 'OR', 'Helena')
hashmap.set(cities, 'NY', 'Brooklyn')
#hashmap.delete(cities, 'NY')
import hashmap

# create a mapping of animal to genus (not necessarily accurate)
animals = hashmap.new()
hashmap.set(animals, 'Dog', 'Canine')
hashmap.set(animals, 'Cat', 'Feline')
hashmap.set(animals, 'Human', 'Sapien')
hashmap.set(animals, 'Wolf', 'Canine')
hashmap.set(animals, 'Jellyfish', 'Scyphozoa')
hashmap.set(animals, 'Octopus', 'Octopus')

# create a basic set of animals and some sounds for them
sounds = hashmap.new()
hashmap.set(sounds, 'Canine', 'woof')
hashmap.set(sounds, 'Sapien', 'hello world')
hashmap.set(sounds, 'Scyphozoa', '...')

# add some more sounds
hashmap.set(sounds, 'Feline', 'meow')
hashmap.set(sounds, 'Octopus', '...')


# print out some sounds
print '-' * 10
print "Wolves make %s sounds" % hashmap.get(sounds, 'Canine')
print "Humans make %s sounds" % hashmap.get(sounds, 'Sapien')

# print some genii
print '-' * 10
print "Dog is of genus %s" % hashmap.get(animals, 'Dog')
print "Octopus is of genus %s" % hashmap.get(animals, 'Octopus')
示例#12
0
文件: ex39_1.py 项目: anandarajm/py
import hashmap

states = hashmap.new()
hashmap.set(states,'california','CA')

print hashmap.get(states,'california')
示例#13
0
import hashmap

aMap = hashmap.new()
hashmap.set(aMap,10,"ten")
hashmap.set(aMap,20,"twenty")
print hashmap.get(aMap,10)
print "Old hashmap:"
hashmap.list(aMap)
hashmap.delete(aMap,10)
hashmap.set(aMap,20,"2*10")
print "New hashmap:"
hashmap.list(aMap)


示例#14
0
#-coding:utf8
# http://learnpythonthehardway.org/book/

import hashmap

# oreate a mapping for states to abbreviation
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, 'Hawaii', 'HI')

#oreate a basio set of states and  some oities in them
cities = hashmap.new()
hashmap.set(cities, 'CA', 'Los Angeles')
hashmap.set(cities, 'Hi', 'Honolulu')
hashmap.set(cities, 'FL', 'Orlando')

# add some more oities
hashmap.set(cities, 'NY', 'New York')
hashmap.set(cities, 'OR', 'Portland')

# print out some oities
print('-' * 10)
print("NY State has: %s" % hashmap.get(cities, 'NY'))
print("Hi State has: %s" % hashmap.get(cities, "HI"))

# print some states
print('-' * 10)
print("Hawaii`s abbreviation is: %s" % hashmap.get(states, 'Hawaii'))
示例#15
0
import hashmap

# create a mapping of state to abbreviation
states = hashmap.new()  # Initializes a Map with the given number of buckets.
hashmap.set(
    states, 'Oregon', 'OR'
)  # In the Map, sets the key to the value, replacing any existing value.
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 their capitals
cities = hashmap.new()
hashmap.set(cities, 'CA', 'Sacramento')
hashmap.set(cities, 'MI', 'Lansing')
hashmap.set(cities, 'FL', 'Tallahassee')

# add some more capitals
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(states, 'Michigan') == 'MI'

# do it by using the state dict, then the cities dict
示例#16
0
import hashmap

#create a mapping of state to abbreviation
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, 'Hawaii', 'HI')

# create a basic set of states and some cities in them
cities = hashmap.new()
hashmap.set(cities, 'CA', 'Los Angeles')
hashmap.set(cities, 'HI', 'Honolulu')
hashmap.set(cities, 'FL', 'Orlando')

#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: %s" % hashmap.get(cities, 'NY')
print "OR State has: %s" % hashmap.get(cities, 'OR')

# print some states
print '-' * 10
print "Hawaii's abbreviation is: %s" % hashmap.get(states, "Hawaii")
print "Florida's abbreviation is: %s" % hashmap.get(states, 'Florida')
import hashmap
country = hashmap.new()
hashmap.set(country, 'VietNam', 'VN')
hashmap.set(country, 'ThaiLan', 'TL')
hashmap.set(country, 'Malaysia', 'ML')
city = hashmap.new()
hashmap.set(country,'VN', 'HaNoi')
hashmap.set(country, 'TL', 'BangKok')
hashmap.set(country, 'ML', 'Kualalumpur')
print "Viet Nam duoc viet gon la: ", hashmap.get(country, 'VietNam')
print "Thu do cua Viet Nam la: ", hashmap.get(city, 'VN')
print "Danh sach: "
hashmap.list(country)
hashmap.list(city)
示例#18
0
import hashmap

#create a mapping of state to abbreviation
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: %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')

#do it by using the stats then cities dict
import hashmap

provinces = hashmap.new()
# Dutch provinces; key is province name, value is its largest city
hashmap.set(provinces, 'North Holland', 'Amsterdam')
hashmap.set(provinces, 'South Holland', 'Rotterdam')
hashmap.set(provinces, 'Utrecht', 'Utrecht')
hashmap.set(provinces, 'Zeeland', 'Middelburg')
hashmap.set(provinces, 'Groningen', 'Groningen')
hashmap.set(provinces, 'Limburg', 'Maastricht')
hashmap.set(provinces, 'Flevoland', 'Almere')
hashmap.set(provinces, 'North Brabant', 'Den Bosch')
hashmap.set(provinces, 'Friesland', 'Leeuwarden')
hashmap.set(provinces, 'Drenthe', 'Assen')
hashmap.set(provinces, 'Gelderland', 'Nijmegen')
hashmap.set(provinces, 'Overijssel', 'Enschede')

hashmap.list(provinces)
print '-' * 10
print hashmap.get(provinces, 'Drenthe')
示例#20
0
import hashmap

#states that I visited and their abbreviations
states = hashmap.new()

hashmap.set(states, 'New-York','NY')
hashmap.set(states, 'Texas','TX')
hashmap.set(states, 'Massachusetts','MA')
hashmap.set(states, 'Rhode-Island','RI')
hashmap.set(states, 'Florida','FL')
hashmap.set(states, 'Maine','ME')
hashmap.set(states, 'Connecticut','CT')


#countries I have visited and the continent

countries = hashmap.new()

hashmap.set(countries,'USA','North-America')
hashmap.set(countries,'Bangladesh','Asia')
hashmap.set(countries,'India','Asia')
hashmap.set(countries,'Saudi-Arabia','Asia')
hashmap.set(countries,'UAE','Asia')
hashmap.set(countries,'Canada','North-America')

print "Please input the name of the state you think you visited."
rqst = raw_input(">>>>>>>>>  ")

st = hashmap.get(states, rqst, 'Not-Visited')

if st == 'Not-Visited':
示例#21
0
print "bucket_id = ", bucket_id
print "returns aMap[bucket_id] =", aMap[bucket_id]
print '=' *50

print '->' * 5, "def get_slot(aMap, key, default=None)",'<-' * 5
print "getting get_slot(aMap, key, default=None)"
get_slot = hashmap.get_slot(aMap, key, value) 
# bucket = get_bucket
bucket = get_bucket
print "bucket = ", bucket
print "returns get_slot = ", get_slot
print '=' *50

print '->' * 5, "def set(aMap, key, default=None)",'<-' * 5
print "getting set(aMap, key, value)"
set1 = hashmap.set(aMap, key, value)
i, k, v = get_slot
print "bucket = ", bucket
print "i, k, v = ", i, k, v
print "aMap contents: ",aMap
print '=' *50

print '->' * 5, "def get(aMap, key, default=None)",'<-' * 5
print "getting get(aMap, key, default=None)"
get = hashmap.get(aMap, key)
print "returns v: = ", get

print '-' * 10, "Reverse engineer part 2", '-' * 10
aMap1 = hashmap.new() # creates aMap1 dict
hashmap.set(aMap1, 'key1', 'value1') # sets value for aMap, key, value. 
# bucket gets get_bucket(aMap, key)
示例#22
0
import hashmap

#Create a mapping of state to abbreviation
states = hashmap.new()
hashmap.set(state,'Oregon','OR')
hashmap.set(state,'Florida','FL')
hashmap.set(state,'California','CA')
hashmap.set(state,'New York','NY')
hashmap.set(state,'Michigan','MI')


#create a basic set of states and some cities in them
cities = {
	'CA':'San Francisco',
	'MI': 'Detroit',
	'FL':'Jacksonville'
}

#add some cities
cities['NY'] = 'New York'
cities['OR'] = 'Portland'

#print some cities
print '-' * 10
print "NY State has: ", cities['NY']
print "OR State has: ", cities['OR']

#print some states
print '-' * 10
print "Michigan's abbreviation is: ", states['Michigan']
print "Florida's abbreviation is: ", states['Florida']
示例#23
0
import hashmap

states = hashmap.new()
hashmap.set(states, 'california', 'CA')

print hashmap.get(states, 'california')
示例#24
0
#!/usr/bin/env python
import hashmap

#create a mapping of state to abbreciation
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:%s" % hashmap.get(cities, "NY")
print "OR state has:%s" % hashmap.get(cities, "OR")

#print some states
print "-" * 10
print "Michigan's abbreciation is :%s" % hashmap.get(states, "Michigan")
print "Florida's abbreviation is:%s" % hashmap.get(
    cities, hashmap.get(states, "Florida"))
import hashmap

# create a mapping of state to abbreviation
states = hashmap.new()
# get_slot gets invoked every time set is called
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')
print "states[174]: ", states[174]
print "states: ", states, "\n"
# print "hash_key: ", hashmap.hash_key(states, 'Oregon')
# print "get_bucket: ", hashmap.get_bucket(states, 'Oregon')
print "get_slot: ", hashmap.get_slot(states, 'Oregon')

# # 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: %s" % hashmap.get(cities, 'NY')
# print "OR State has: %s" % hashmap.get(cities, 'OR')
示例#26
0
文件: ex39_2.py 项目: kuiwa/learngit
# -*- coding: utf-8 -*-

import hashmap

# create a mapping of state to abbreviation
#states = hashmap.new()
#hashmap.set(states, 'New York', 'NY')
cities = hashmap.new()
hashmap.set(cities, 'NY', 'New York')

print '-' * 10
print "NY State has: %s" % hashmap.get(cities, 'NY')

#print "OR State has: %s" % hashmap.get(states, 'OR')
# print every state abbreviation
#print '-' * 10
#hashmap.list(states)
#Learnpythonthehardway
# Exercise 39 - hashmap example

import hashmap

# create a mapping of state to abbreviation
races = hashmap.new()
hashmap.set(races, 'Dwarf', 'DWF')
hashmap.set(races, 'Elf', 'ELF')
hashmap.set(races, 'Halfling', 'HLF')
hashmap.set(races, 'Human', 'HUM')
hashmap.set(races, 'Dragonborn', 'DRG')
hashmap.set(races, 'Gnome', 'GNM')
hashmap.set(races, 'Half-elf', 'HEF')
hashmap.set(races, 'Half-orc', 'HOC')
hashmap.set(races, 'Tiefling', 'TFL')

# create a basic set of states and some cities in them
traits = hashmap.new()
hashmap.set(traits, 'DWF', 'Dwarven Combat Training')
hashmap.set(traits, 'ELF', 'Elf Weapon Training')
hashmap.set(traits, 'HLF', 'Naturally Stealthy')
hashmap.set(traits, 'HUM', 'Feat Bonus')
hashmap.set(traits, 'DRG', 'Breath Weapon')

# add some more cities
hashmap.set(traits, 'GNM', 'Gnome Cunning')
hashmap.set(traits, 'HEF', 'Skill Versatility')
hashmap.set(traits, 'HOC', 'Relentless Endurance')
hashmap.set(traits, 'TFL', 'Infernal Legacy')
示例#28
0
import hashmap

# create a mapping of state to abbreviation
states = hashmap.new()
hashmap.set(states, 'Baden-Wuerttemberg', 'BW') #1
hashmap.set(states, 'Freistaat Bayern', 'BY') #2
hashmap.set(states, 'Berlin', 'BE') #3
hashmap.set(states, 'Brandenburg', 'BB') #4
hashmap.set(states, 'Bremen', 'HB') #5
hashmap.set(states, 'Hamburg', 'HH') #6
hashmap.set(states, 'Hessen', 'HE') #7
hashmap.set(states, 'Niedersachsen', 'NI') #8
hashmap.set(states, 'Mecklenburg-Vorpommern', 'MV') #9
hashmap.set(states, 'Nordrhein-Westfalen', 'NW') #10
hashmap.set(states, 'Rheinland-Pfalz', 'RP') #11
hashmap.set(states, 'Saarland', 'SL') #12
hashmap.set(states, 'Freistaat Sachsen', 'SN') #13
hashmap.set(states, 'Sachsen-Anhalt', 'ST') #14
hashmap.set(states, 'Schleswig-Holstein', 'SH') #15
hashmap.set(states, 'Freistaat Thueringen', 'TH') #16

# create a basic set of states and some cities in them
cities = hashmap.new()
hashmap.set(cities, 'BW', 'Stuttgart')
hashmap.set(cities, 'BY', 'Muenchen')
hashmap.set(cities, 'BE', 'None')
hashmap.set(cities, 'BB', 'Potsdam')
hashmap.set(cities, 'HB', 'None')
hashmap.set(cities, 'HH', 'None')
hashmap.set(cities, 'HE', 'Wiesbaden')
hashmap.set(cities, 'NI', 'Hannover')
示例#29
0
import hashmap
import collections
# states = hashmap.new()
# hashmap.set(states, "Oregon", "OR")

cities = hashmap.new()
hashmap.set(cities, "SZ", "shenzhen")
hashmap.set(cities, "BJ", "beijing")

print('-' * 10)
#
print("Shenzen:", hashmap.get(cities, "SZ"))
print("Beijing:", hashmap.get(cities, "BJ"))
# print("OR:",hashmap.get(states, "Oregon"))
# print("ABC:", hashmap.get(states, "abc"))

print('-' * 10)
hashmap.list(cities)

print("==" * 20)
print(hashmap.get(cities, "GZ", "Dont Exit"))

testOrderDict = {}
testOrderDict['1'] = "a"
testOrderDict['3'] = 'dc'
testOrderDict['2'] = 'fc'
new = collections.OrderedDict(sorted(testOrderDict.items()),
                              key=lambda t: t[1])
for k, v in testOrderDict.items():
    print("OrderDict:", k)
for k, v in new.items():
示例#30
0
def main():
    # create a mapping of state to abbreviation
    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: %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')

    # 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 in one line?
    city = hashmap.get(cities, 'TX', 'Does Not Exist')
    print "The city for the state 'TX' is: %s" % city
示例#31
0
# EXERCISE 39 TEST FILE - Kiswanto_D

import hashmap

# create a mapping of state to abbreviation
states = hashmap.new()
hashmap.set(states, 'Jawa Barat', 'Jabar')
hashmap.set(states, 'Jawa Timur', 'Jatim')
hashmap.set(states, 'Kalimantan Selatan', 'Kalsel')
hashmap.set(states, 'DKI Jakarta', 'DKI')
hashmap.set(states, 'Sumatra Utara', 'Sumut')

# create a basic set of states and some cities in them
cities = hashmap.new()
hashmap.set(cities, 'Jabar', 'Bandung')
hashmap.set(cities, 'Jatim', 'Surabaya')
hashmap.set(cities, 'DKI', 'Jakpus')

# add some more cities
hashmap.set(cities, 'Kalsel', 'Pangandaran')
hashmap.set(cities, 'Sumut', 'Medan')

# print out some cities
print '-' * 10
print "Jabar State has: %s" % hashmap.get(cities, 'Jabar')
print "Jatim State has: %s" % hashmap.get(cities, 'Jatim')

# print some states
print '-' * 10
print "Jawa Barat's abbreviation is: %s" % hashmap.get(states, 'Jawa Barat')
print "Kalimantan Selatan's abbreviation is: %s" % hashmap.get(
# Extra exercise.
# Date: 2014-16-25

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 "---- 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)
示例#33
0
import hashmap

def divider():
    print '-' * 10

# create a mapping of state to abbreviation
states = hashmap.new()
hashmap.set(states, 'Orgeon', 'OR')
hashmap.set(states, 'Florida', 'FL')
hashmap.set(states, 'California', 'CA')
hashmap.set(states, 'New York', 'NY')
hashmap.set(states, 'Michigan,' 'MI')
hashmap.set(states, 'Massachusetts', 'MA')

# 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')
hashmap.set(cities, 'MA', 'Boston')

# print out some cities
divider()
print 
示例#34
0
import hashmap_d

states = hashmap_d.new()
hashmap_d.set(states,'Oregon','OR')


cities = hashmap_d.new()
hashmap_d.set(cities,'CA','San Francisco')

print '-' * 20
print "%s"% hashmap_d.get(cities,'CA')

import hashmap
states = hashmap.new()
hashmap.set(states,'CN','china')
hashmap.set(cities,'china','Beijing')

print '-' * 20
print "%s"% hashmap.get(states,'CN')

hashmap.get_slot(cities,'CN','china')
hashmap.list(states)
hashmap.list(cities)

mystuff = {'apple':'I am apples!'}
print mystuff['apple']

def apple():
	print "i am apples!"

apple()
#Study Drill ex39a
import hashmap

#create a mapping of state abbreviation
states = hashmap.new()
hashmap.set(states, "Wisconsin", "WI")
hashmap.set(states, "Michigan", "MI")
hashmap.set(states, "Illinois", "IL")

#create a basic set of states and some cities
cities = hashmap.new()
hashmap.set(cities, "WI", "Milwaukee")
hashmap.set(cities, "MI", "Detroit")
hashmap.set(cities, "IL", "Chicago")

#cities printing
print("-"*10)
for i in states:
	if i:
		for k, v in i:
			v
			print ("%s, %s" % (hashmap.get(cities, v), v))
# The Exercise 39 Test Suite
# Various function calls to test hashmap.py, which is
# part of Exercise 39.

import hashmap

# create a mapping of state to abbreviation
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, 'Michican','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 citiies
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
示例#37
0
# EXERCISE 39 TEST FILE - Kiswanto_D

import hashmap

# create a mapping of state to abbreviation
states = hashmap.new()
hashmap.set(states, 'Jawa Barat', 'Jabar')
hashmap.set(states, 'Jawa Timur', 'Jatim')
hashmap.set(states, 'Kalimantan Selatan', 'Kalsel')
hashmap.set(states, 'DKI Jakarta', 'DKI')
hashmap.set(states, 'Sumatra Utara', 'Sumut')

# create a basic set of states and some cities in them
cities = hashmap.new()
hashmap.set(cities, 'Jabar', 'Bandung')
hashmap.set(cities, 'Jatim', 'Surabaya')
hashmap.set(cities, 'DKI', 'Jakpus')

# add some more cities
hashmap.set(cities, 'Kalsel', 'Pangandaran')
hashmap.set(cities, 'Sumut', 'Medan')

# print out some cities
print '-' * 10
print "Jabar State has: %s" % hashmap.get(cities, 'Jabar')
print "Jatim State has: %s" % hashmap.get(cities, 'Jatim')

# print some states
print '-' * 10
print "Jawa Barat's abbreviation is: %s" % hashmap.get(states, 'Jawa Barat')
print "Kalimantan Selatan's abbreviation is: %s" % hashmap.get(states, 'Kalimantan Selatan')
示例#38
0
import hashmap

# create a mapping of state to abbreviation
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 ciites
hashmap.set(cities, 'NY', 'New York')
hashmap.set(cities, 'OR', 'Portland')

#print out some ciites
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')
示例#39
0
import hashmap

#states that I visited and their abbreviations
states = hashmap.new()

hashmap.set(states, 'New-York', 'NY')
hashmap.set(states, 'Texas', 'TX')
hashmap.set(states, 'Massachusetts', 'MA')
hashmap.set(states, 'Rhode-Island', 'RI')
hashmap.set(states, 'Florida', 'FL')
hashmap.set(states, 'Maine', 'ME')
hashmap.set(states, 'Connecticut', 'CT')

#countries I have visited and the continent

countries = hashmap.new()

hashmap.set(countries, 'USA', 'North-America')
hashmap.set(countries, 'Bangladesh', 'Asia')
hashmap.set(countries, 'India', 'Asia')
hashmap.set(countries, 'Saudi-Arabia', 'Asia')
hashmap.set(countries, 'UAE', 'Asia')
hashmap.set(countries, 'Canada', 'North-America')

print "Please input the name of the state you think you visited."
rqst = raw_input(">>>>>>>>>  ")

st = hashmap.get(states, rqst, 'Not-Visited')

if st == 'Not-Visited':
    print "Nope,%s is %s" % (rqst, st)