-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage_people_more.py
More file actions
53 lines (41 loc) · 1.08 KB
/
storage_people_more.py
File metadata and controls
53 lines (41 loc) · 1.08 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
#! /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)
def store_list(*names):
for name in names:
store(name)
if __name__ == '__main__':
init()
store_list('wang hao', 'wang mei', 'wang yan kan', 'wang yu tao', 'tan mu mao')
showPeople()