-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path0301.py
More file actions
53 lines (41 loc) · 1.27 KB
/
0301.py
File metadata and controls
53 lines (41 loc) · 1.27 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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(data, label, name)
if people:
people.append(full_name)
else:
data[label][name] = [full_name]
def init(data):
labels = 'first', 'middle', 'last'
for label in labels:
data[label] = {}
MyNames={}
init(MyNames)
store(MyNames, 'wang hao')
store(MyNames, 'wang qiang')
store(MyNames, 'zhang bao')
print lookup(MyNames, 'first', 'zhang')
# def hello(parameter_list):
# 'this is a hello'
# print parameter_list
# print hello.__doc__
# girls = ['alice', 'bernice', 'clarice']
# boys = ['chris', 'arnold', 'bob']
# print [(g,b) for g in girls for b in boys if g[0] == b[0]]
# tmpObj={}
# tmpObj.pop
# [tmpObj.setdefault(b[0], []).append(b) for b in boys]
# print [(g,''.join(tmpObj[g[0]])) for g in girls if g[0] in tmpObj]
# print [x*x for x in range(10) if not x%3 ]
# print [(x,y) for x in range(3) for y in range(3)]
# a=[1,2,3,4]
# b=['a', 'b', 'c','d']
# for x,y in zip(a, b):
# print x, y
# for index, string in enumerate(b):
# print index, string