Created
March 24, 2014 16:08
-
-
Save slopeofhope81/9743335 to your computer and use it in GitHub Desktop.
brushing up python #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
storage = {} | |
storage["first"]={} | |
storage["middle"]={} | |
storage["last"]={} | |
me = "steve seung lim" | |
storage["first"]["steve"] = me | |
storage["middle"]["seung"] = me | |
storage["last"]["lim"] = me | |
wife = "annie haeseong kim" | |
storage["first"].setdefault("annie",[]).append(wife) | |
storage["middle"].setdefault("haeseong",[]).append(wife) | |
storage["last"].setdefault("kim",[]).append(wife) | |
def init(data): | |
data["first"] = {} | |
data["middle"] = {} | |
data["last"] = {} | |
database = {} | |
init(database) | |
# print database | |
def lookup(data,label,name): | |
return data[label].get(name) | |
def store(data, full_name): | |
names = full_name.split() | |
if len(names) == 2: names.insert(1,"") | |
labels = "first", "middle", 'last' | |
for label, name in zip(labels, names): | |
people =lookup(database, label, name) | |
if people: | |
people.append(full_name) | |
else: | |
data[label][name]=[full_name] | |
store(storage, "chloe lim") | |
print storage | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment