【发布时间】:2016-05-29 07:14:56
【问题描述】:
我应该使用哪些高级 Python 库来使以下代码更加简洁和整洁?
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
def most_classes(dict):
for item in dict:
count = 0
max = 0
teacher = None
for course in dict[item]:
count += 1
if count > max:
max = count
teacher = item
return teacher
【问题讨论】:
标签: python dictionary