-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage_people_update.py
More file actions
54 lines (43 loc) · 1.06 KB
/
storage_people_update.py
File metadata and controls
54 lines (43 loc) · 1.06 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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2020 pi <pi@raspberrypi>
#
# Distributed under terms of the MIT license.
"""
存储人名
"""
result = {}
labels = 'first','middle','last'
def init():
result.setdefault(labels[0], {})
result.setdefault(labels[1], {})
result.setdefault(labels[2], {})
def lookup(data,label,first_name):
return data.get(label, {}).setdefault(first_name, [])
def store(name):
names = name.strip().split()
if len(names) == 2:
names.insert(1, '')
elif not len(names):
print("Please input names like 'ha li luya'")
return False
for label,key in zip(labels,names):
people = lookup(result,label,key)
if people:
if name not in people:
people.append(name)
else:
people.append(name)
def showPeople():
print(result)
if __name__ == '__main__':
init()
store('wang hao')
showPeople()
store('wang hao')
showPeople()
store('tan mu xun')
store('wang yu hao')
showPeople()