fork download
  1. #定义列表数据
  2. score_list =[65, 92, 78, 90, 45, 83, 57, 96]
  3. #先要定义好字典的键值对
  4. score_dict={
  5. 'high':[],
  6. 'middle':[],
  7. 'low':[]
  8. }
  9. #循环遍历
  10. for score in score_list:
  11. #验证
  12. if score>=90:
  13. score_dict['high'].append(score)
  14. elif score>=60:
  15. score_dict['middle'].append(score)
  16. else:
  17. score_dict['low'].append(score)
  18. #打印字典
  19. print(score_dict)
Success #stdin #stdout 0.08s 7996KB
stdin
Standard input is empty
stdout
{'high': [92, 90, 96], 'middle': [65, 78, 83], 'low': [45, 57]}