forked from jiangxiaolulu/songqin-testdev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
38 lines (26 loc) · 877 Bytes
/
Copy pathdebug.py
File metadata and controls
38 lines (26 loc) · 877 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
# coding=utf8
# 读取文件内容
def getFileContent(filePath):
fh = open(filePath)
fc = fh.read()
fh.close()
return fc
content = getFileContent('debug.txt')
# 将学生年龄信息存入age2names中
students = content.split(',')
age2names = {}
for student in students:
name, age = student.split(':')
if age in age2names:
age2names[age].append(name)
else:
age2names[age] = [name]
curMax = 0 # 人数最多的年龄 的人数 ,初识值设置为 0
maxCountAge = None # 人数最多的年龄 ,初识值设置为 None
# 根据age2names 计算出人数最多的年龄
for age, names in age2names.items():
count = len(names)
if count >= curMax:
curMax = count
maxCountAge = age
print('人数最多的年龄是 %s岁' % maxCountAge)