forked from foxli180/BeginningPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch6-p100-parameter2.py
More file actions
30 lines (24 loc) · 819 Bytes
/
ch6-p100-parameter2.py
File metadata and controls
30 lines (24 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#-*-coding:utf-8-*- #enable chinese char displaying
def init(data):
data['first'] = {}
data['middle'] = {}
data['last'] = {}
def lookup(data,label,name):
return data[label].get(name)
def store(data, *fullnames): #now we can send more than 1 names at 1 time
for fullname in fullnames:
names = fullname.split()
if len(names) == 2: names.insert(1,'')
labels = 'first','middle','last'
for name,label in zip(names,labels):
people = lookup(data,label,name)
if people:
people.append(fullname)
else:
data[label][name]=[fullname]
mynames2 = {}
init(mynames2)
store(mynames2,'Fox lee','Hello world','Fox zhang','Fox hello zhang')#
print mynames2['first']
print mynames2['middle']
print mynames2['last']