-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage_people.py
More file actions
48 lines (38 loc) · 957 Bytes
/
storage_people.py
File metadata and controls
48 lines (38 loc) · 957 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /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 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):
currentList = result.get(label, {}).setdefault(key, [])
if name not in currentList:
result[label][key].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()