fork download
  1. lloyd = {
  2. "name": "Lloyd",
  3. "homework": [90.0, 97.0, 75.0, 92.0],
  4. "quizzes": [88.0, 40.0, 94.0],
  5. "tests": [75.0, 90.0]
  6. }
  7.  
  8. def average( what ):
  9. if not isinstance( what, list ):
  10. return what
  11. if not all( isinstance(item, (int, long, float, complex)) for item in what ):
  12. return what
  13. else:
  14. return sum( what ) / len( what )
  15.  
  16. for k, v in lloyd.iteritems():
  17. print k, average(v)
Success #stdin #stdout 0.08s 8672KB
stdin
Standard input is empty
stdout
quizzes 74.0
tests 82.5
name Lloyd
homework 88.5